Spatial Indexes for ESRI Shape datasets

From fmepedia


This page contains an example FME Workspace created by an fmepedia user.
  See the attached files list at the foot of this page for the zip file containing this workspace.  



Q) I need to create a Spatial Index for my Shape data. Can I do this with FME?

A) This is possible by using ESRI's Python geoprocessor in an FME shutdown script.

Create a blank Python startup script: If you need to do any pre-processing in Python, you can skip this step. Due to a limitation in FME's Python interface, shutdown scripts cannot access Macro Values unless there is a startup script, even if it's just a new line.

Force FME to use Python 2.4: Go to the Tools menu, and select “Edit Header...” Enter “FME_PYTHON_VERSION 2.4” at the beginning of the header. This forces fme to use Python 2.4, regardless of what your computer's default Python version is. The python interface in ArcGIS 9.2 does not work with other versions of Python. This will change when ArcGIS 9.3 is released, which only supports Python 2.5. Luckily, FME supports Python 2.3, 2.4, and 2.5.

Modify the shutdown script to meet your needs Open shutdown.py in a text editor. If you don't need spatial indexing, you can comment out line 57 (add a # to the beginning of the line), or delete the spatialIndex function. This function will extract the paths to every shapefile in the workspace, and add a spatial index to all of them. If you only want to index certain shapefiles, you can comment out line 57, and uncomment line 60 (remove the # form the beginning of the line) and replace "path_to_shape.shp" with the path to the shapefile you want to index (remember to escape your "\"s. C:\Temp should be C:\\Temp).

If you need attribute indexing, you can modify line 67. You will need to uncomment the line by removing the #. Replace path_to_shape.shp with the path to your shapefile (remember to escape your "\"s. C:\Temp should be C:\\Temp) should have the path to your shapefile, and the second set of “”s should have the name of the attribute you wish to index.

Add the script to your workspace: Now you can either copy and paste the script into the Shutdown Python Script, or copy the shutdown.py file to the same directory as your workspace, and set the shutdown python script to “import shutdown”.

Attached Files
filesizedate
End_Python_Script.fmw38.1 kB05/27/08
index.php------
shutdown.py2.4 kB05/27/08
User Comments Add a new comment