Select to view content in your preferred language

MakeFeatureLayer where_clause selection not maintained during projection

1867
3
Jump to solution
05-18-2012 06:49 AM
CyrilleMedard_de_Chardon
Emerging Contributor
#import, environment etc.. is omitted for brevity  prjString = "PROJCS['World_Mercator',GEOGCS['GCS_WGS_1984',DATUM['D_WGS_1984',SPHEROID['WGS_1984',6378137.0,298.257223563]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Mercator'],PARAMETER['False_Easting',0.0],PARAMETER['False_Northing',0.0],PARAMETER['Central_Meridian',0.0],PARAMETER['Standard_Parallel_1',0.0],UNIT['Meter',1.0]];-20037700 -30198300 10000;-100000 10000;-100000 10000;0.001;0.001;0.001;IsHighPrecision"  #Create a layer based only on rows with 'src' attribute equal to 'YVR' arcpy.MakeFeatureLayer_management("FlightPaths", "YVR_layer", "\"src\" = 'YVR'")  #Project the layer data arcpy.Project_management("YVR_layer", "YVR_Proj", prjString)


The problem I'm encountering is that Project is selecting the full source data set rather than the layer selection. The arcpy.MakeFeatureLayer_management operation has created the layer 'YVR_layer' from 'FlightPaths' successfully and selected the desired rows. When I pass 'YVR_layer' to arcpy.Project_management it projects all the rows from 'FlightPaths' rather than those from 'FlightPaths' as selected.

Any idea why this may be happening. Data is included below.
0 Kudos
1 Solution

Accepted Solutions
GraemeBrowning
Frequent Contributor
Over on Stack Exchange GIS I have posted some code to demonstrate that what Cyrille is trying to do will work if you do the Make Feature Layer with a where clause by starting on a shapefile.  It does not if you start on a file geodatabase feature class.

Consequently, it appears to be a bug with either Make Feature Layer or Project.

The workaround of using Copy Features on the file geodatabase feature class to create an equivalent shapefile first is not desirable so I think the next step should be to find/submit a bug report on this.

I think Nobbir's workaround should work too, and be preferable because it does not duplicate data, but I don't think Cyrille's procedure should not work on a feature class when it does on a shapefile.

- Graeme

View solution in original post

0 Kudos
3 Replies
NobbirAhmed
Esri Regular Contributor
Selection and definition query on layers are not supported by the Project tool: all features in the dataset referenced by the layer will be projected.

If you want to project selected features only, consider using the Copy Features tool. Copy Features only copies selected features and honors the output coordinate system geoprocessing environment.

So, after Make Feature Layer, set the output coordinate system environment with your desired coordinate system and then run Copy Features.
0 Kudos
GraemeBrowning
Frequent Contributor
Over on Stack Exchange GIS I have posted some code to demonstrate that what Cyrille is trying to do will work if you do the Make Feature Layer with a where clause by starting on a shapefile.  It does not if you start on a file geodatabase feature class.

Consequently, it appears to be a bug with either Make Feature Layer or Project.

The workaround of using Copy Features on the file geodatabase feature class to create an equivalent shapefile first is not desirable so I think the next step should be to find/submit a bug report on this.

I think Nobbir's workaround should work too, and be preferable because it does not duplicate data, but I don't think Cyrille's procedure should not work on a feature class when it does on a shapefile.

- Graeme
0 Kudos
CyrilleMedard_de_Chardon
Emerging Contributor
I agree with Graeme that this inconsistent behaviour should be categorized more as a geodatabase bug than something that is not supported.
I have used the Copy Features method for my work but was looking for a more efficient manner.

Thanks for clearing up the issue.

Regards,
Cyrille
0 Kudos