[FWTools] ogr: how to create a data source?

Bryan Keith bryan at geomega.com
Tue Oct 18 11:29:12 EDT 2005


Thanks, Frank.

That worked great.  My way of finding my way around ogr is by looking at 
ogr.py (in an editor that supports folding).  I'm going to take a better 
look at the examples.

Bryan

Frank Warmerdam wrote:

>On 10/18/05, Bryan Keith <bryan at geomega.com> wrote:
>  
>
>>If this isn't the correct list for this question, let me know.
>>
>>I have some Python code that creates a new shapefile.  It uses these ogr
>>calls:
>>
>>ogrSDS = ogr.Open(os.path.abspath(""),1)
>>ogrSLayerNew = ogrSDS.CreateLayer(myfilename, None, geomtype)
>>
>>This works fine if a shapefile already exists in the directory.
>>However, when no shapefiles (or any other data sources) exist in the
>>directory then the ogr.Open method fails.  Is there a way to create a
>>data source?  Or what am I supposed to do here?
>>    
>>
>
>Bryan,
>
>>From the "tigerpoly.py" example script, you can see the following
>sequence for creating a shapefile datasource.  If "outfile" is a filename
>ending in .shp then a single shapefile is created.  Otherwise OGR will
>attempt to create a directory of that name.
>
>Note that the only way to start creating shapefiles in an existing empty
>directory is to open single-file datasources.
>
>shp_driver = ogr.GetDriverByName( 'ESRI Shapefile' )
>shp_ds = shp_driver.CreateDataSource( outfile )
>
>Best regards,
>--
>---------------------------------------+--------------------------------------
>I set the clouds in motion - turn up   | Frank Warmerdam, warmerdam at pobox.com
>light and sound - activate the windows | http://pobox.com/~warmerdam
>and watch the world go round - Rush    | Geospatial Programmer for Rent
>
>
>  
>


More information about the FWTools mailing list