Hi,
I'm loading data from a GeoJSON object in python. I'm sure I am properly assigning my point coordinates in "geometry" key like this:
and creating a featureSet from the cases dict (GeoJSON) and load it to my hosted feature layer in AGOL.
But in my AGOL's map viewer, all points are concentrated in [0,0] coordinates. Checking the service URL, whenever I query the features and return them in HTML or in JSON format, it shows the correct (x,y) geometry. But when I return them in geojson, it shows wrong (x,y) values. Any idea how this is even possible? Thank you!
JSON:
HTML:
GeoJSON:
Solved! Go to Solution.
This works fine now. I just reprojecting the coordinates I'm getting from geocoding addresses. Geocoding returns coords value in 4326 so I just convert those values to 3857 in my code. Thank you Egge-Jan Pollé for the idea.
from arcgis import geometry def reproject_coords(coords): input_geom = [{'x': coords[0], 'y': coords[1]}] result = geometry.project(geometries=input_geom, in_sr=4326, out_sr=3857) return [result[0]['x'], result[0]['y']]
Hi Aldwin Gregorio,
I guess the CRS (Coordinate Reference System) of your featureSet is something like 102100 or 3857 (most probably both), which is Web Mercator, while the CRS of your input data is not...
You can check this by asking for it's spatial_reference like this:
fs.spatial_reference
{'wkid': 102100, 'latestWkid': 3857}
So, you will have to convert your input data to Web Mercator during the import process.
HTH,
Egge-Jan
Hi Egge-Jan Pollé,
Thank you for your reply. I checked the spatial_reference of my featureset and saw that the CRS is in {'wkid': 4326}. So I explicitly changed the CRS by overriding the spatial_reference property of my FeatureSet to {'wkid': 102100, 'latestWkid': 3857}. However, my points are still displayed in the wrong locations.
I am looking into this module (arcgis.features module — arcgis 1.8.0 documentation ) and trying to look for a function that can convert the spatial reference of my input featureset, but spatial_reference is the only available one from the list. I tried including the datum_transformation when I'm calling the edit_features() but getting this error instead.
Checking the module show me this in the layer.py
`
Checking the from_geojson method in feature.py show me this.
Is there an available method/function that will transform my featureset to the 3857?
This works fine now. I just reprojecting the coordinates I'm getting from geocoding addresses. Geocoding returns coords value in 4326 so I just convert those values to 3857 in my code. Thank you Egge-Jan Pollé for the idea.
from arcgis import geometry def reproject_coords(coords): input_geom = [{'x': coords[0], 'y': coords[1]}] result = geometry.project(geometries=input_geom, in_sr=4326, out_sr=3857) return [result[0]['x'], result[0]['y']]
Hi Aldwin Gregorio,
Good to hear that my suggestion was useful and good to see that you managed to get the conversion right 🙂
BR,
Egge-Jan