How to use the ogr.GetDriver function in ogr

To help you get started, we’ve selected a few ogr examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sourcepole / ogrtools / ogrtools / pyogr / ogr2ogr.py View on Github external
#/*      Open data source.                                               */
#/* -------------------------------------------------------------------- */
    if isinstance(pszDataSource, basestring):
        poDS = ogr.Open(pszDataSource, False)
    else:
        poDS = pszDataSource

#/* -------------------------------------------------------------------- */
#/*      Report failure                                                  */
#/* -------------------------------------------------------------------- */
    if poDS is None:
        print("FAILURE:\n" +
              "Unable to open datasource `%s' with the following drivers." % pszDataSource)

        for iDriver in range(ogr.GetDriverCount()):
            print("  ->  " + ogr.GetDriver(iDriver).GetName())

        return False

#/* -------------------------------------------------------------------- */
#/*      Try opening the output datasource as an existing, writable      */
#/* -------------------------------------------------------------------- */
    poODS = None
    poDriver = None

    if bUpdate:
        poODS = ogr.Open(pszDestDataSource, True)
        if poODS is None:

            if bOverwrite or bAppend:
                poODS = ogr.Open(pszDestDataSource, False)
                if poODS is None:
github developmentseed / landsat-util / landsat / third_party / ogr2ogr.py View on Github external
print( "Usage: ogr2ogr [--help-general] [-skipfailures] [-append] [-update] [-gt n]\n" + \
            "               [-select field_list] [-where restricted_where] \n" + \
            "               [-progress] [-sql ] \n" + \
            "               [-spat xmin ymin xmax ymax] [-preserve_fid] [-fid FID]\n" + \
            "               [-a_srs srs_def] [-t_srs srs_def] [-s_srs srs_def]\n" + \
            "               [-f format_name] [-overwrite] [[-dsco NAME=VALUE] ...]\n" + \
            "               [-simplify tolerance]\n" + \
            #// "               [-segmentize max_dist] [-fieldTypeToString All|(type1[,type2]*)]\n" + \
            "               [-fieldTypeToString All|(type1[,type2]*)] [-explodecollections] \n" + \
            "               dst_datasource_name src_datasource_name\n" + \
            "               [-lco NAME=VALUE] [-nln name] [-nlt type] [-dim 2|3] [layer [layer ...]]\n" + \
            "\n" + \
            " -f format_name: output file format name, possible values are:")

    for iDriver in range(ogr.GetDriverCount()):
        poDriver = ogr.GetDriver(iDriver)

        if poDriver.TestCapability( ogr.ODrCCreateDataSource ):
            print( "     -f \"" + poDriver.GetName() + "\"" )

    print( " -append: Append to existing layer instead of creating new if it exists\n" + \
            " -overwrite: delete the output layer and recreate it empty\n" + \
            " -update: Open existing output datasource in update mode\n" + \
            " -progress: Display progress on terminal. Only works if input layers have the \"fast feature count\" capability\n" + \
            " -select field_list: Comma-delimited list of fields from input layer to\n" + \
            "                     copy to the new layer (defaults to all)\n" + \
            " -where restricted_where: Attribute query (like SQL WHERE)\n" + \
            " -sql statement: Execute given SQL statement and save result.\n" + \
            " -skipfailures: skip features or layers that fail to convert\n" + \
            " -gt n: group n features per transaction (default 200)\n" + \
            " -spat xmin ymin xmax ymax: spatial query extents\n" + \
            " -simplify tolerance: distance tolerance for simplification.\n" + \
github sourcepole / ogrtools / ogrtools / pyogr / ogr2ogr.py View on Github external
print("Usage: ogr2ogr [--help-general] [-skipfailures] [-append] [-update] [-gt n]\n" +
          "               [-select field_list] [-where restricted_where] \n" +
          "               [-progress] [-sql ] \n" +
          "               [-spat xmin ymin xmax ymax] [-preserve_fid] [-fid FID]\n" +
          "               [-a_srs srs_def] [-t_srs srs_def] [-s_srs srs_def]\n" +
          "               [-f format_name] [-overwrite] [[-dsco NAME=VALUE] ...]\n" +
          "               [-simplify tolerance]\n" +
          #// "               [-segmentize max_dist] [-fieldTypeToString All|(type1[,type2]*)]\n" +
          "               [-fieldTypeToString All|(type1[,type2]*)] [-explodecollections] \n" +
          "               dst_datasource_name src_datasource_name\n" +
          "               [-lco NAME=VALUE] [-nln name] [-nlt type] [-dim 2|3] [layer [layer ...]]\n" +
          "\n" +
          " -f format_name: output file format name, possible values are:")

    for iDriver in range(ogr.GetDriverCount()):
        poDriver = ogr.GetDriver(iDriver)

        if poDriver.TestCapability(ogr.ODrCCreateDataSource):
            print("     -f \"" + poDriver.GetName() + "\"")

    print(" -append: Append to existing layer instead of creating new if it exists\n" +
          " -overwrite: delete the output layer and recreate it empty\n" +
          " -update: Open existing output datasource in update mode\n" +
          " -progress: Display progress on terminal. Only works if input layers have the \"fast feature count\" capability\n" +
          " -select field_list: Comma-delimited list of fields from input layer to\n" +
          "                     copy to the new layer (defaults to all)\n" +
          " -where restricted_where: Attribute query (like SQL WHERE)\n" +
          " -sql statement: Execute given SQL statement and save result.\n" +
          " -skipfailures: skip features or layers that fail to convert\n" +
          " -gt n: group n features per transaction (default 20000)\n" +
          " -spat xmin ymin xmax ymax: spatial query extents\n" +
          " -simplify tolerance: distance tolerance for simplification.\n" +
github qgiscloud / qgis-cloud-plugin / qgiscloud / pyogr / ogr2ogr.py View on Github external
"         being updated.")

        if poODS is not None:
            poDriver = poODS.GetDriver()

#/* -------------------------------------------------------------------- */
#/*      Find the output driver.                                         */
#/* -------------------------------------------------------------------- */
    if not bUpdate:
        poDriver = ogr.GetDriverByName(pszFormat)
        if poDriver is None:
            print("Unable to find driver `%s'." % pszFormat)
            print("The following drivers are available:")

            for iDriver in range(ogr.GetDriverCount()):
                print("  ->  %s" % ogr.GetDriver(iDriver).GetName())

            return False

        if poDriver.TestCapability(ogr.ODrCCreateDataSource) == False:
            print("%s driver does not support data source creation." % pszFormat)
            return False

#/* -------------------------------------------------------------------- */
#/*      Special case to improve user experience when translating        */
#/*      a datasource with multiple layers into a shapefile. If the      */
#/*      user gives a target datasource with .shp and it does not exist, */
#/*      the shapefile driver will try to create a file, but this is not */
#/*      appropriate because here we have several layers, so create      */
#/*      a directory instead.                                            */
#/* -------------------------------------------------------------------- */
        if EQUAL(poDriver.GetName(), "ESRI Shapefile") and \
github qgiscloud / qgis-cloud-plugin / qgiscloud / pyogr / ogr2ogr.py View on Github external
print("Usage: ogr2ogr [--help-general] [-skipfailures] [-append] [-update] [-gt n]\n" + \
            "               [-select field_list] [-where restricted_where] \n" + \
            "               [-progress] [-sql ] \n" + \
            "               [-spat xmin ymin xmax ymax] [-preserve_fid] [-fid FID]\n" + \
            "               [-a_srs srs_def] [-t_srs srs_def] [-s_srs srs_def]\n" + \
            "               [-f format_name] [-overwrite] [[-dsco NAME=VALUE] ...]\n" + \
            "               [-simplify tolerance]\n" + \
            #// "               [-segmentize max_dist] [-fieldTypeToString All|(type1[,type2]*)]\n" + \
            "               [-fieldTypeToString All|(type1[,type2]*)] [-explodecollections] \n" + \
            "               dst_datasource_name src_datasource_name\n" + \
            "               [-lco NAME=VALUE] [-nln name] [-nlt type] [layer [layer ...]]\n" + \
            "\n" + \
            " -f format_name: output file format name, possible values are:")

    for iDriver in range(ogr.GetDriverCount()):
        poDriver = ogr.GetDriver(iDriver)

        if poDriver.TestCapability(ogr.ODrCCreateDataSource):
            print("     -f \"" + poDriver.GetName() + "\"")

    print(" -append: Append to existing layer instead of creating new if it exists\n" + \
            " -overwrite: delete the output layer and recreate it empty\n" + \
            " -update: Open existing output datasource in update mode\n" + \
            " -progress: Display progress on terminal. Only works if input layers have the \"fast feature count\" capability\n" + \
            " -select field_list: Comma-delimited list of fields from input layer to\n" + \
            "                     copy to the new layer (defaults to all)\n" + \
            " -where restricted_where: Attribute query (like SQL WHERE)\n" + \
            " -sql statement: Execute given SQL statement and save result.\n" + \
            " -skipfailures: skip features or layers that fail to convert\n" + \
            " -gt n: group n features per transaction (default 200)\n" + \
            " -spat xmin ymin xmax ymax: spatial query extents\n" + \
            " -simplify tolerance: distance tolerance for simplification.\n" + \
github FBK-WED / wed-pipe / data_acquisition / pat-ckan / ogr2reclinejs.py View on Github external
def __init__(self,infile,verbose=False):
		'''
				create a object with the source file (infile = geodata source)
				'''
		supportedformats = []
		self.sr_wgs84 = osr.SpatialReference()
		self.sr_wgs84.ImportFromEPSG(4326)

		driver = None
		for g in range(0,ogr.GetDriverCount()):
			supportedformats.append(ogr.GetDriver(g).GetName())
			driver= ogr.GetDriver(g)
			datasource = driver.Open(infile)
			if datasource != None:
				self.datasource = datasource
				self.formatfound = ogr.GetDriver(g).GetName()
				break

		if datasource is None:
			message = 'Could not find the driver for %s' % infile
			if verbose:
				message += "\n"
				message += "List of supported drivers:"
				for sf in supportedformats:
					message += "- %s\n" % sf
			raise Exception,message
github sourcepole / ogrtools / qgis / ogrprocessing / ogralgorithm.py View on Github external
def drivers(self):
        list = []
        for iDriver in range(ogr.GetDriverCount()):
            list.append("%s" % ogr.GetDriver(iDriver).GetName())
        return list
github FBK-WED / wed-pipe / data_acquisition / pat-ckan / ogr2reclinejs.py View on Github external
def __init__(self,infile,verbose=False):
		'''
				create a object with the source file (infile = geodata source)
				'''
		supportedformats = []
		self.sr_wgs84 = osr.SpatialReference()
		self.sr_wgs84.ImportFromEPSG(4326)

		driver = None
		for g in range(0,ogr.GetDriverCount()):
			supportedformats.append(ogr.GetDriver(g).GetName())
			driver= ogr.GetDriver(g)
			datasource = driver.Open(infile)
			if datasource != None:
				self.datasource = datasource
				self.formatfound = ogr.GetDriver(g).GetName()
				break

		if datasource is None:
			message = 'Could not find the driver for %s' % infile
			if verbose:
				message += "\n"
				message += "List of supported drivers:"
				for sf in supportedformats:
					message += "- %s\n" % sf
			raise Exception,message

		self.layers_fields = []