Proceed to GeoCommunity Home Page


SpatialNewsGIS Data DepotGeoImaging ChannelGIS and MappingSoftwareGIS JobsGeoBids-RFPsGeoCommunity MarketplaceGIS Event Listings
HomeLoginAccountsAboutContactAdvertiseSearchFAQsForumsCartFree Newsletter

Sponsored by:


TOPICS
Today's News

Submit News

Feature Articles

Product Reviews

Education

News Affiliates

Discussions

Newsletters

Email Lists

Polls

Editor's Corner


SpatialNews Daily Newswire!
Subscribe now!

Latest Industry Headlines
SiteVision GIS Partnership With City of Roanoke VA Goes Live
Garmin® Introduces Delta™ Upland Remote Trainer with Beeper
Caliper Offers Updated Chile Data for Use with Maptitude 2013
Southampton’s Go! Rhinos Trail Mapped by Ordnance Survey
New Approach to Measuring Coral Growth Offers Valuable Tool for Reef Managers
Topo ly - Tailor-Fit for Companies' Online Mapping Needs

Latest GeoBids-RFPs
Nautical Charts*Poland
Software & Telemetry GPS
Spatial Data Management-DC
Geospatial and Mapping-DC
Next-Gen 911-MO

Recent Job Opportunities
Planner/GIS Specialist
Team Leader- Grape Supply Systems
Geospatial Developer

Recent Discussions
Raster images
cartographic symbology
Telephone Exchange areas in Europe
Problem showcasing Vector map on Windows CE device
Base map

GeoCommunity Mailing List
 
Mailing List Archives

Subject: [gislist] batch import dbf to shapefiles
Date:  04/27/2007 02:55:00 PM
From:  Louisa Wood



Hi all,

Thanks for the helpful suggestions correcting the typos. I've now managed to
find a way to do this. I've pasted the code below in case anyone else wants
to do the same thing. From other messages I've had from others, the use of
forward vs back slash in file pathways seems not to be an issue in later
versions of Python (I'm using 2.5). I've also used double and single slashes
in the script below and all seems to work fine.



The reference to toolbox paths can have those spaces (as the toolbox name
has the space in it) - even though generally spaces in pathnames are
problematic for ArcGIS.



The last sticking point I had was with the MakeXYEventLayer_management
method: it kept returning an error saying the parameters were not valid. I
couldn't understand this as I had been following the template in the ArcGIS
help. Eventually I found out how to fix it by using the Modelbuilder to do a
MakeXYEventLayer with the same inputs as I was trying to use. I then
exported the model as a python script, to see if there were any differences
in the code. The spatial reference was completely different (see below) from
what I had thought was OK to use (a pathname to the .prj file) based on
other examples of scripts I had found online.



By the way - this is good for ArcGIS 9.0 and possibly also 9.1. In 9.2 ESRI
changed the need to import win32com.client to another module called
arcgisscripting. So if you're using 9.2 you'll have to modify this & maybe
look into other differences.



So there you go. Hope it helps if you need something similar one day :-)



Louisa





#
---------------------------------------------------------------------------

#batch_dbfXY_to_pt_shp.py

# Created on: on 2007 04 25

# Created by Louisa Wood

# Script is designed to loop through a set of tables in a geodatabase, which
contain lat/long information.

# An XY event is generated for each table, then exported as a shapefile to a
specified folder

#

#
---------------------------------------------------------------------------



# Import system modules

import sys, string, os, win32com.client



# Create the Geoprocessor object

gp = win32com.client.Dispatch("esriGeoprocessing.GpDispatch.1")



#confirm license

gp.SetProduct("ArcInfo")



# Load required toolboxes...

gp.AddToolbox("C:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Data Management
Tools.tbx")

gp.AddToolbox("C:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Conversion
Tools.tbx")



#set input workspace

gp.workspace=("C:\RNoutdbase")



outworkspace=("C:\RNoutshp")



try:

#Get a list of the tables in the input workspace

fcs=gp.ListTables()

#Loop through the list of tables

fcs.Reset()

fc=fcs.Next()





while fc:

outlayer=fc.split('.')[0]



#confirm that input and output files and names are correct

print "Will make XYEvent layer " + outlayer + " using " + fc



# Process: Make XY Event Layer...

gp.MakeXYEventLayer_management(fc, "x_Coord", "y_Coord", outlayer,
"GEOGCS['GCS_WGS_1984',DATUM['D_WGS_1984',SPHEROID['WGS_1984',6378137.0,298.
257223563]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]]:-1000
0.000000 -10000.000000 100000.000000:0.000000 100000.000000:0.000000
100000.000000")



#confirm that XYEventLayer has been created & with correct name

print "XYEvent layer " + outlayer + " using " + fc + " now made."



# Process: Feature Class To Shapefile (multiple)...

gp.CopyFeatures(outlayer, outworkspace+'/'+outlayer)



#confirm that XYEvent Layer has been converted to shapefile

print "Event Layer " + outlayer + " has been converted to shapefile"



fc=fcs.Next()



except:

gp.AddMessage(gp.GetMessages(2))

print gp.GetMessages(2)





_______________________________________________
gislist mailing list
gislist@lists.geocomm.com
http://lists.geocomm.com/mailman/listinfo/gislist

_________________________________
This list is brought to you by
The GeoCommunity
http://www.geocomm.com/

Sponsored by:

For information
regarding
advertising rates
Click Here!

Copyright© 1995-2012 MindSites Group / Privacy Policy

GeoCommunity™, Wireless Developer Network™, GIS Data Depot®, and Spatial News™
including all logos and other service marks
are registered trademarks and trade communities of
MindSites Group