1

I suspect that there is no easier way to do this, other than developing this as a two-step process with a temporary output (which seems somewhat wasteful). If I have to, I'll just create a temporary output and use the Project tool as a second step.

I have an ETL process (python script) that involves creating field mappings and merging data from our Enterprise SQL-Server Express database (in our local State Plane NAD1983 coordinate system) to a file geodatabase whose schema is in WGS1984 Geographic Coordinates. I've noticed that the output is close but not quite correctly aligned (it is "forced" into the coordinate system of the output gdb).

"Is there a way to use Merge (with field mappings) and somehow enforce a datum transformation (in my case WGS_1984_ITRF00_To_NAD_1983) in the same step?".

There is nothing in the "Merge" tool dialog indicating a parameter that would allow me to do apply a transformation. Similarly there is nothing in the "Project" dialog allowing me to add field mappings.

This is just a small snippet of code to show how I'm currently doing this.

# ID_PREFIX (temporary)
fldmap_IDP = arcpy.FieldMap()
fldmap_IDP.mergeRule = 'First'
fldmap_IDP.addInputField(input_lyr, "ID_PREFIX")
fieldmappings.addFieldMap(fldmap_IDP)

# END MAPPING FIELDS

print("Field Mappings are Complete ... Ready to Merge ...")
# FINALLY - DO THE MERGE
arcpy.Merge_management(input_lyr, out_fc, fieldmappings)

EDIT: I tried adding the transformation to the geoprocessing environment as suggested but (assuming I did so correctly), it did not help. The result was still off by about 3 feet (see my code below).

# FINALLY - DO THE MERGE
arcpy.env.outputCoordinateSystem = arcpy.SpatialReference("WGS 1984") # 4326
arcpy.env.geographicTransformations = "WGS_1984_ITRF00_To_NAD_1983" # from 2248
arcpy.Merge_management(input_lyr, out_fc, fieldmappings)`

enter image description here

  • I'm confused how your field mapping works with a merge. What does mergeRule = 'First' do when you're using the field mappings in a merge? Logically I wouldn't think it does anything since values don't get combined with a merge. – Emil Brundage Jun 13 at 21:18
  • 2
    What happens if you set the transformation in the gp environment? – mkennedy Jun 13 at 22:56
  • I'm hoping that what The projectionista Melita suggests, will do the trick. I think @Emil that I am including some fields that do not collide in the mapping so that they are in the output (they are otherwise excluded) so the mergeRule doesn't matter in my case? Interesting that you point out that "values don't get combined". I suppose that the features are added together and don't ever become a single feature? I'm merging into a feature class that serves as an empty schema (has 0 features). – jbchurchill Jun 14 at 12:56
2

You can create a new feature class and use a data access insert cursor, projecting each Geometry with projectAs.

Sample code; update with correct values for spatial reference, geometry type, etc.:

mergeFcs = ["fc1", "fc2"] #merge feature classes

outFc = "out_feature_class"

#---

import arcpy

outPath, outName = os.path.split (outFc)
arcpy.CreateFeatureclass_management (outPath, outName, "geomtype", #geom type
                                     mergeFcs [0], #template for fields
                                     spatial_reference = "WGS1984") #spatial reference

#fields for cursor
#will have to play with to mimic field mappings
flds = [f.name for f in arcpy.ListFields (outFc)] + ["SHAPE@"]

for fc in mergeFcs:
    with arcpy.da.SearchCursor (fc, flds) as sCurs:
        with arcpy.da.InsertCursor (outFc, flds) as iCurs:
            for row in sCurs:
                row = list (row) #allows updating
                geom = row [-1] #get geom
                geom = geom.projectAs ("WGS1984", "WGS_1984_ITRF00_To_NAD_1983") #project with datum transformation
                row [-1] = geom #update row
                iCurs.insertRow (row) #insert row
  • I'm not sure yet that this will help me here but it is an interesting approach and I may need to try it before I decide. – jbchurchill Jun 14 at 12:57
0

Actually despite the edit to my question, further examination of the method described in a comment from @mkennedy led me to try using the same (fully descriptive) geoprocessing environment used when using the the Project Tool from the Projections and Transformations toolbox and the results are AS GOOD AS when using Project. The screenshot shows the measurement in feet between the original data (red) and projected (green) from the project tool (or from the script; the 2 are identical). I think this result using this transformation is as good as I can possibly get (improved code below the screenshot). I did not realize that all those specifics made a real difference in the result since the short version is pretty much what I enter in the Project tool dialog. I just dug these specifics out of the "Results" tab after running the Project tool and it made a world of difference.

enter image description here

print("Field Mappings are Complete ... Ready to Merge ...")
# FINALLY - DO THE MERGE
#arcpy.env.outputCoordinateSystem = arcpy.SpatialReference("WGS 1984") # 4326
arcpy.env.outputCoordinateSystem = "GEOGCS['GCS_WGS_1984',DATUM['D_WGS_1984',SPHEROID['WGS_1984',6378137.0,298.257223563]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]]"
#arcpy.env.geographicTransformations = "WGS_1984_ITRF00_To_NAD_1983" # from 2248
arcpy.env.geographicTransformations = "WGS_1984_(ITRF00)_To_NAD_1983"
arcpy.env.inputCoordinateSystem = "PROJCS['NAD_1983_StatePlane_Maryland_FIPS_1900_Feet',GEOGCS['GCS_North_American_1983',DATUM['D_North_American_1983',SPHEROID['GRS_1980',6378137.0,298.257222101]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Lambert_Conformal_Conic'],PARAMETER['False_Easting',1312333.333333333],PARAMETER['False_Northing',0.0],PARAMETER['Central_Meridian',-77.0],PARAMETER['Standard_Parallel_1',38.3],PARAMETER['Standard_Parallel_2',39.45],PARAMETER['Latitude_Of_Origin',37.66666666666666],UNIT['Foot_US',0.3048006096012192]]"
arcpy.Merge_management(input_lyr, out_fc, fieldmappings)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.