convert coordinates on the fly?

2838
7
Jump to solution
06-28-2012 10:33 AM
KevinBell
Occasional Contributor III
I have a big list of data that includes XY's in one spatial ref, but I'd love to use another spatial ref when I insert into a point object.  Other wise I have to insert it into a temp FC, then project it, then delete the temp FC.  Is there a more elegant method?
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
markdenil
Occasional Contributor III
You should declare the spatial reference of the INPUT coordinates.
The cursor picks up the TARGET spatial reference from the feature class.

<quote> from "Setting a cursor's spatial reference":
[... source is a list of state plane coords, target is UTM...]
When you open the insert cursor on the feature class, you set its spatial reference to state plane, declaring that you want the geometries you're inserting to be converted from state plane to UTM.
<unquote>

View solution in original post

0 Kudos
7 Replies
MichaelMiller2
Occasional Contributor III
Check out Corpscon. I've used it in the past and works well to take a text file with coordinate pairs + other attribute info and re-project and write to a new file.

http://www.tec.army.mil/corpscon/
0 Kudos
JasonScheirer
Occasional Contributor III
SearchCursors will let you set a spatial reference, you can insert points at a different spatial ref than what the feature class is set to.
0 Kudos
KevinBell
Occasional Contributor III
SearchCursors will let you set a spatial reference, you can insert points at a different spatial ref than what the feature class is set to.


So if I do this...

c = arcpy.InsertCursor(myFC, differentSpatialRef)
for r in rows:
    x = c.newRow()
    pnt = arcpy.Point()
    pnt.X = r[1] # x in old spatRef 
    pnt.Y = r[2] # y n old spatRef
    x.shape = pnt
    c.insertRow(x)


...then the XY's will be in the new SF?
0 Kudos
JasonScheirer
Occasional Contributor III
It will treat the coordinates in your points as being in that spatial reference, and then reproject them to the spatial reference of the feature class when it inserts them.
0 Kudos
KevinBell
Occasional Contributor III
This is still producing NAD27 points and I'm trying to get NAD83...  What am I missing here?


godataselect = "SELECT gd.primary_key, ........... 'Assault Aggravated')"

rows = dbCursor.execute(godataselect)

incs = r'C:\Program Files (x86)\ArcGIS\Desktop10.0\Coordinate Systems\Projected Coordinate Systems\State Plane\NAD 1927 (US Feet)\NAD 1927 StatePlane Utah Central FIPS 4302.prj'
inSF = arcpy.SpatialReference(incs)

outcs = 'C:\\Program Files (x86)\\ArcGIS\\Desktop10.0\\Coordinate Systems\\Projected Coordinate Systems\\State Plane\\NAD 1983 (US Feet)\\NAD 1983 StatePlane Utah Central FIPS 4302 (US Feet).prj'
outSF = arcpy.SpatialReference(outcs)

arcpy.CreateFeatureclass_management ('default.gdb', 'nad83', 'POINT', 'default.gdb\\template') #NAD83
arcpy.DefineProjection_management ('default.gdb\\nad83', outSF)

c = arcpy.InsertCursor('default.gdb\\nad83', inSF)

for r in rows:
    print r
    rr = c.newRow()
    
    rr.xml_primary_key = r[0].strip()
    rr.officer_id = r[1].strip()
    rr.report_date = r[2]
 
    pnt = arcpy.Point()
    pnt.X = r[18] #nad 27 x
    pnt.Y = r[19] #nad 27 y
    rr.shape = pnt
    
    c.insertRow(rr)

del rows, c
0 Kudos
markdenil
Occasional Contributor III
You should declare the spatial reference of the INPUT coordinates.
The cursor picks up the TARGET spatial reference from the feature class.

<quote> from "Setting a cursor's spatial reference":
[... source is a list of state plane coords, target is UTM...]
When you open the insert cursor on the feature class, you set its spatial reference to state plane, declaring that you want the geometries you're inserting to be converted from state plane to UTM.
<unquote>
0 Kudos
KevinBell
Occasional Contributor III
^^^ thanks for pointing that out! 

I'm getting closer...  Now I just need to figure out how to get the geographic transformation to be applied so I'm not 200ft off to the east!

fixt:  arcpy.env.geographicTransformations = 'NAD_1927_To_NAD_1983_NADCON'
0 Kudos