Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_convert_arcgis_polygon_with_z_values_to_geojson_polygon(self):
input = {
'rings': [
[
[41.8359375, 71.015625, 1],
[56.953125, 33.75, 1],
[21.796875, 36.5625, 1],
[41.8359375, 71.015625, 1]
]
],
'spatialReference': {
'wkid': 4326
}
}
output = arcgis2geojson(input)
self.assertEqual(output['coordinates'], [
[
[41.8359375, 71.015625, 1],
[21.796875, 36.5625, 1],
[56.953125, 33.75, 1],
[41.8359375, 71.015625, 1]
]
])
self.assertEqual(output['type'], 'Polygon')
def test_convert_arcgis_polygon_to_geojson_polygon(self):
input = {
'rings': [
[
[41.8359375, 71.015625],
[56.953125, 33.75],
[21.796875, 36.5625],
[41.8359375, 71.015625]
]
],
'spatialReference': {
'wkid': 4326
}
}
output = arcgis2geojson(input)
self.assertEqual(output['coordinates'], [
[
[41.8359375, 71.015625],
[21.796875, 36.5625],
[56.953125, 33.75],
[41.8359375, 71.015625]
]
])
self.assertEqual(output['type'], 'Polygon')
def test_convert_arcgis_point_with_z_value_to_geojson_point(self):
input = {
'x': -66.796875,
'y': 20.0390625,
'z': 1,
'spatialReference': {
'wkid': 4326
}
}
output = arcgis2geojson(input)
self.assertEqual(output['coordinates'], [-66.796875, 20.0390625, 1])
self.assertEqual(output['type'], 'Point')
def test_convert_string_json_to_string_json(self):
input = json.dumps({
'x': -66.796875,
'y': 20.0390625,
'spatialReference': {
'wkid': 4326
}
})
output = arcgis2geojson(input)
self.assertIsInstance(output, str)
output = json.loads(output)
self.assertEqual(output['coordinates'], [-66.796875, 20.0390625])
self.assertEqual(output['type'], 'Point')
[41.8359375, 71.015625],
[56.953125, 33.75],
[21.796875, 36.5625],
[41.8359375, 71.015625]
]
],
'spatialReference': {
'wkid': 4326
}
},
'attributes': {
'OBJECTID': 123
}
}
output = arcgis2geojson(input)
self.assertEqual(output['id'], 123)
def test_id_must_be_string_or_number(self):
input = {
'x': -66.796875,
'y': 20.0390625,
'spatialReference': {
'wkid': 4326
},
'attributes': {
'OBJECTID': 123,
'some_field': {
'not a number': 'or a string'
}
}
}
output = arcgis2geojson(input, 'some_field')
# 'some_field' isn't a number or string - fall back to OBJECTID
self.assertEqual(123, output['id'])
def test_convert_arcgis_polyline_with_z_values_to_geojson_linestring(self):
input = {
'paths': [
[
[6.6796875, 47.8125, 1],
[-65.390625, 52.3828125, 1],
[-52.3828125, 42.5390625, 1]
]
],
'spatialReference': {
'wkid': 4326
}
}
output = arcgis2geojson(input)
self.assertEqual(output['coordinates'], [
[6.6796875, 47.8125, 1],
[-65.390625, 52.3828125, 1],
[-52.3828125, 42.5390625, 1]
])
self.assertEqual(output['type'], 'LineString')
'geometry': {
'rings': [
[
[41.8359375, 71.015625],
[56.953125, 33.75],
[21.796875, 36.5625],
[41.8359375, 71.015625]
]
],
'spatialReference': {
'wkid': 4326
}
}
}
output = arcgis2geojson(input)
self.assertEqual(output['geometry']['coordinates'], [
[
[41.8359375, 71.015625],
[21.796875, 36.5625],
[56.953125, 33.75],
[41.8359375, 71.015625]
]
])
self.assertEqual(output['geometry']['type'], 'Polygon')
self.assertEqual(output['properties'], None)
[-122.49, 45.48],
[-122.64, 45.49]
],
[
[-83, 35],
[-74, 35],
[-74, 41],
[-83, 41]
]
],
'spatialReference': {
'wkid': 4326
}
}
output = arcgis2geojson(input)
self.assertEqual(output['coordinates'], [
[
[
[-122.63, 45.52],
[-122.64, 45.49],
[-122.49, 45.48],
[-122.52, 45.5],
[-122.57, 45.53],
[-122.63, 45.52]
]
],
[
[
[-83, 35],
[-74, 35],
[-74, 41],
def test_convert_arcgis_polyline_to_geojson_linestring(self):
input = {
'paths': [
[
[6.6796875, 47.8125],
[-65.390625, 52.3828125],
[-52.3828125, 42.5390625]
]
],
'spatialReference': {
'wkid': 4326
}
}
output = arcgis2geojson(input)
self.assertEqual(output['coordinates'], [
[6.6796875, 47.8125],
[-65.390625, 52.3828125],
[-52.3828125, 42.5390625]
])
self.assertEqual(output['type'], 'LineString')