Select to view content in your preferred language

Using Python, can't get Batch Project outputs to save in a feature dataset

4458
11
09-14-2011 05:35 AM
JamesGraham
Regular Contributor
When attempting to batch project in ArcGIS (using either arcpy or arcgisscripting), I cannot get my geoprocessing results to drop into the feature dataset that I specify. The results instead are dropped in the root of the Geodatabase (*.mdb).

Here's an abbreviated version of what I have so far:

import arcgisscripting, os
gp = arcgisscripting.create(9.3)

#set date
dmy = datetime.now()
currentDate = str(dmy.month) + "-" + str(dmy.day) + "-" + str(dmy.year)

outputfolder = gp.getparameterastext(0) #where we're going to drop the gdb
citydata = gp.getparameterastext(1)

gp.workspace = outputfolder
projectedfolder = os.path.join(outputfolder, "projected")
gp.CreateFolder_management(*os.path.split(projectedfolder))
gdb = "Projected_Data_" + currentDate + ".mdb"

#set coordinate system
outputCS = gp.CreateObject("SpatialReference")
outputCS.createFromFile(os.path.join(gp.getinstallinfo()['InstallDir'], "Coordinate Systems\\Geographic Coordinate Systems\\North America\\NAD 1983.prj"))
transformation = ""

gp.AddMessage("Creating City feature dataset")
gp.CreateFeatureDataset(os.path.join(projectedfolder, gdb), "City", outputCS)

gp.AddMessage("Loading in City feature classes")
arcpy.BatchProject_management(citydata, os.path.join(projectedfolder, gdb, "City"), outputCS, "", transformation)


Obviously, the part I'm having trouble with is the Output Path in the last line. I've also hard-coded the path to the "City" feature dataset, but still drops it in the root. Any ideas?
0 Kudos
11 Replies
NobbirAhmed
Esri Regular Contributor
Are the spatial refereces of your input data and that of the feature dataset different? Could you add this line after the call to BatchProject and see what messages are returned?

gp.AddMessage(gp.GetMessages())
0 Kudos
JamesGraham
Regular Contributor
Are the spatial refereces of your input data and that of the feature dataset different? Could you add this line after the call to BatchProject and see what messages are returned?

gp.AddMessage(gp.GetMessages())


Thanks for your reply, NobbirAhmed.  I believe the fds and the input have the same spatial references.  Note that the outputCS variable is used for creating the new fds and also serves as the SR parameter in the BatchProject.  Inserting the gp.AddMessage(gp.GetMessages()) produced no errors.

FYI, I cross-posted this at gis.stackexchange and discovered that this is a known issue (with the script version only, for some reason):  http://gis.stackexchange.com/questions/14585/using-python-batch-project-output-wont-drop-in-a-featur...

According to the poster on gis.stackexchange, this behavior is "As Designed".  I'm a bit baffled by that, but would love hear why this is intentional.
0 Kudos
NobbirAhmed
Esri Regular Contributor
Yes (and unfortunately) this is not implemented for Project tool (same for Batch Project as it just calls Project in a loop).

So, if you want to send your output to a Feature Dataset it won't go there - instead, a standalone feature class will be created in the geodatabase containing the feature dataset.

In order to enforce the output to go to the Feature Dataset workspace we'd have to disable setting an output coordinate system other than that of the destination Feature Dataset's. In such a scenario, the user wouldn't have the ability to change the spatial reference (to any other projection). This would've essentially hindered the main objective of the project tool.

I guess, caught between two following scenarios, we decided to go for the current design (option# 2):

1. Let the user send the output to Feature Dataset (when the input is a feature class) without the freedom to select any spatial reference.

2. Let the user select any spatial reference by accepting the fact the output will be put in the geodatabase.
0 Kudos
JamesGraham
Regular Contributor
Thanks for the excellent reply, NobbirAhmed.

I now see the reasoning behind the current design of the script version of Batch Project.  This is just one man's opinion, but I think some slight modification could be made without too much heartache (easy for me to say):

1.  Batch project to a feature dataset with a user-specified Spatial Reference (SR) that is the same as the feature dataset:
   -  Tool works, output placed in proper feature dataset. 

2.  Batch project to a feature dataset with a user-specified Spatial Reference (SR) that is different than that of a feature dataset:
   -  Tool works, but output placed in root of geodatabase
   -  Warning message indicates that output was not placed in desired location
0 Kudos
NobbirAhmed
Esri Regular Contributor
Thanks for the excellent suggestion James. I'm going to log your suggestion. As Batch Project tool is deprected in 10.0 and onward, we'll try to make the changes to Project tool.

Thanks again.
0 Kudos
NobbirAhmed
Esri Regular Contributor
CORRECTION: Batch Project is not deprecated.

So, we'll consider the suggestion for both Project abd Batch Project tools.
0 Kudos
DuarteCarreira
Frequent Contributor
fast forward to 2012...

I can't project a feature class from one dataset to another. It always places the output in the root of the output gdb.

So what is the workflow designed by esri for this simple, frequent (I imagine) use case?

Thanks,
Duarte
0 Kudos
NobbirAhmed
Esri Regular Contributor
I can't project a feature class from one dataset to another. It always places the output in the root of the output gdb.


Please read posting# 4 - it states why this behavior is by design.
0 Kudos
GregoryStewart
New Contributor
Please read posting# 4 - it states why this behavior is by design.


As a college instructor, option 2 makes no sense to me (or my students) and it is inconsistent with the behavior of other tools.  For example, when I export from ArcMap to a feature dataset, I can ONLY export in the coordinate system of the feature dataset.  Most other tools seem to abide by the idea that if I want put output into a feature dataset, I understand that it will be in the coordinate system of the feature dataset because feature datasets by definition, have defined coordinate systems. We tell them that if a geographic/datum transformation is required, they need to use the Project or Batch Project tools and it is frustrating that those tools deal with feature datasets differently.
 
For example, I have an exercise where students download base data for the Olympic National Park.  The data is all in NAD_1927_UTM_Zone10N but the coordinate systems is not defined on any of the shapefiles.  There are about 25 shapefiles, so they import them into a feature dataset to define the coordinate system.  Then they can use the Project or Batch project tool to import the features to a new feature dataset, but it doesn�??t appear that they can project them into an existing feature dataset.  Instead, they Project them into scratch geodatabase and then export them into the existing feature dataset.

It seems like you should be able to Project or Batch Project into existing feature datasets with the understanding that the coordinate system is set by the choice of destination, the feature dataset.
0 Kudos