Projection with cursors

846
10
08-09-2011 01:26 AM
RogerLoweth
New Contributor
According to the ArcGIS 10 help, one should be able to re-project using cursors thus:

#update cursor to fc and input lat lon
    rows = arcpy.UpdateCursor(fc, inCRS)
    for row in rows:
        pnt = arcpy.Point()
        pnt.X = lon_value
        pnt.Y = lat_value
        row.shape = pnt
        row.shape = pnt
        rows.updateRow(row)
    del row, rows
    #project to outGEOGCS
    rows = arcpy.SearchCursor(fc, outGEOGCS)
    for row in rows:
        feat = row.shape
        coord = feat.getPart()
        longitude = coord.X
        latitude = coord.Y
    del row, rows
    #project to outPROJCS
    rows = arcpy.SearchCursor(fc, outPROJCS)
    for row in rows:
        feat = row.shape
        coord = feat.getPart()
        easting = coord.X
        northing = coord.Y
    del row, rows

This code attempts to read in a point in one CRS and transform it to a different datum and then to another projection.

I get no errors but the re-projection simply does not work. Unfortunately I can't use the GDAL/OGR libraries in my corporate environment (I wish I could!!).

Anyone know of a workaround please??

Also, this is DESPERATELY slow!!

Roger
Tags (2)
0 Kudos
10 Replies
JakeSkinner
Esri Esteemed Contributor
What is you initial coordinate system, and which coordinate system are you attempting to re-project to?
0 Kudos
ChrisSnyder
Regular Contributor III
The spatial refernce object is the 3rd parameter in the update & search cursor statments (2nd parameer for the insercursor statment). So it would be:

rows = arcpy.UpdateCursor(fc, "", inCRS)
#instead of
rows = arcpy.UpdateCursor(fc, inCRS)
0 Kudos
ChrisSnyder
Regular Contributor III
Is there a reason you are using the cursor instead of the Project tool?
0 Kudos
RogerLoweth
New Contributor
What is you initial coordinate system, and which coordinate system are you attempting to re-project to?


From AGD84 to GDA94 and MGA50. Why would that make a difference?
0 Kudos
RogerLoweth
New Contributor
The spatial refernce object is the 3rd parameter in the update & search cursor statments (2nd parameer for the insercursor statment). So it would be:

rows = arcpy.UpdateCursor(fc, "", inCRS)
#instead of
rows = arcpy.UpdateCursor(fc, inCRS)


That was it! Many, many thanks Chris.

I'm using cursors instead of the project tool in the hope it will be faster. Both methods seem very slow though.

R
0 Kudos
RogerLoweth
New Contributor
That was it! Many, many thanks Chris.

I'm using cursors instead of the project tool in the hope it will be faster. Both methods seem very slow though.

R


I spoke too soon!!

The code runs OK and it is now quite fast (using in-memory feature classes). However, the results for latitude, longitude, easting and northing are always the same, no matter what input/output datums and projections I specify. What seems to happen is that the latitude and longitude project in WGS84 and the datum transformation itself does not work. I've tried this using searchcursors and updatecursors with the same result. Any ideas?? Will project_management work on in-memory feature classes?

(I am already specifying arcpy.env.geographicTransformations so ArcGIS knows which one to use).

R
0 Kudos
ChrisSnyder
Regular Contributor III
Hands down, it would be way faster to use the Project tool that do multiple passes with cursors. I could be wrong, but I'm not completely sure that the cursors honor the arcpy.env.geographicTransformations setting...
0 Kudos
MathewCoyle
Frequent Contributor
My understanding is that you can use an in_memory feature layer as an input to a project tool, but not an output.
0 Kudos
KentWilliams
New Contributor II
My understanding is that you can use an in_memory feature layer as an input to a project tool, but not an output.


I don't see anything in the documentation that indicates you cannot send the results of a arcpy.Project_management operation to an in-memory feature class. 

Just specify your output as "in_memory\\reprojected" or something similar.  When you're done with it, if you want to manually clear it out of memory, just use the arcpy.Delete_management tool, specifying it exactly as in the project tool.

Of course, just because the documentation doesn't say anything about requiring a physical storage output doesn't mean it isn't true.  You're just gonna have to try it!
0 Kudos