Adding feature with geographic coordinate

860
1
04-03-2017 04:53 AM
HN1
by
New Contributor II

Hi !

I am quite new to use REST API and trying to add point feature to my feature service right now.

I successfully added features but locations were very different from where I expected.

My data has only geometry in latitude and longitude, so I suppose what I need to do is transform lat, lon values to web mercator projection before adding data.

My question is that;

1) Can I specify spatial reference in add feature operation?

2) If I cannot specify the spatial reference in the operation, how can I transform lot & lon to web mercator coordinate values via REST API before add data?

If this kind of question was solved before, please suggest URL for the thread.

Thank you!

0 Kudos
1 Reply
RandyBurton
MVP Alum

Try using "projectAs" as illustrated in line 11 below.  A bit more of this example is shown here.

import arcpy  

# WGS 1984 : (4326) Lat/Lon  
x = -122.478470  
y = 37.819369 

# If you know the reference numbers, you can use this:
# WGS 1984 : (4326) Lat/Lon  
# WGS 1984 Web Mercator (auxiliary sphere) : (102100) or (3857)  

ptGeometry = arcpy.PointGeometry(arcpy.Point(x,y),arcpy.SpatialReference(4326)).projectAs(arcpy.SpatialReference(3857)) 

print ptGeometry.JSON  
print ptGeometry.firstPoint.X, ptGeometry.firstPoint.Y ‍‍‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos