Closed blordcastillo closed 10 years ago
The online help for CreateFeatureClass has this Note: "When you use a Template Feature Class its spatial reference is ignored." Also, the arcpy.da.InsertCursor function doesn't seem to support a "spatial_reference" argument (even though one help page says it does), so to set the spatial reference of the new feature class PublicSchools to the same as the schoolPublicDESE feature class (i.e., the template fc), I added a line like this before the call to arcpy.CreateFeatureclass_management:
descDESE = arcpy.Describe(u'schoolPublicDESE')
... and then used it in the existing line that creates the new feature class, like this:
arcpy.CreateFeatureclass_management(arcpy.env.workspace, u'PublicSchools',"POINT", u'schoolPublicDESE', spatial_reference=descDESE.spatialReference)
This should help prevent the "spatial reference" warning message when you try to add your populated PublicSchools feature class to an open ArcMap document.
I think I got around the spatial reference problem by using these lines:
spatial_ref = arcpy.Describe(u'schoolPublicDESE').spatialReference
arcpy.CreateFeatureclass_management(arcpy.env.workspace, u'PublicSchools',"POINT", u'schoolPublicDESE',"DISABLED","DISABLED",spatial_ref)
Do not modify idToSchool. You can define the search cursor before the insert cursor if you want.
There are eight St. Louis County schools whose CtyDist fields are erroneously coded without a leading "0", e.g. 96101 instead of 096101, and one school that is coded as 115 (St. Louis City) instead of 096 (St. Louis County). As a result, these 9 schools don't get "picked up" by my script for inclusion in the new feature class.
Yes, those schools are outside the scope of what we have right now, as we would have to apply outside information to solve the problem.
In this case, you have your knowledge that the data is bad. But we could further deal with this by having a county boundary to test for schools with an incorrect county ID or a list of previous schools to update rather than rebuild the table from scratch.
Assignment 4 is posted. For data for this assignment, use the file geodatabase available as a zip file at https://www.dropbox.com/s/lcjodja7ix8oruh/Assignment4.gdb.zip