Python ogr.OFTInteger() Examples
The following are 5
code examples of ogr.OFTInteger().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
ogr
, or try the search function
.
Example #1
Source File: _conftest.py From pyeo with GNU General Public License v3.0 | 6 votes |
def create_temp_shape(self, name, point_list): vector_file = os.path.join(self.temp_dir.name, name) shape_driver = ogr.GetDriverByName("ESRI Shapefile") # Depreciated; replace at some point vector_data_source = shape_driver.CreateDataSource(vector_file) vector_layer = vector_data_source.CreateLayer("geometry", self.srs, geom_type=ogr.wkbPolygon) ring = ogr.Geometry(ogr.wkbLinearRing) for point in point_list: ring.AddPoint(point[0], point[1]) poly = ogr.Geometry(ogr.wkbPolygon) poly.AddGeometry(ring) vector_feature_definition = vector_layer.GetLayerDefn() vector_feature = ogr.Feature(vector_feature_definition) vector_feature.SetGeometry(poly) vector_layer.CreateFeature(vector_feature) vector_layer.CreateField(ogr.FieldDefn("class", ogr.OFTInteger)) feature = ogr.Feature(vector_layer.GetLayerDefn()) feature.SetField("class", 3) vector_data_source.FlushCache() self.vectors.append(vector_data_source) # Check this is the right thing to be saving here self.vector_paths.append(vector_file)
Example #2
Source File: _conftest.py From pyeo with GNU General Public License v3.0 | 5 votes |
def create_100x100_shp(self, name): """Cretes a shapefile with a vector layer named "geometry" containing a 100mx100m square , top left corner being at wgs coords 10,10. This polygon has a field, 'class' with a value of 3. Left in for back-compatability""" # TODO Generalise this vector_file = os.path.join(self.temp_dir.name, name) shape_driver = ogr.GetDriverByName("ESRI Shapefile") # Depreciated; replace at some point vector_data_source = shape_driver.CreateDataSource(vector_file) vector_layer = vector_data_source.CreateLayer("geometry", self.srs, geom_type=ogr.wkbPolygon) ring = ogr.Geometry(ogr.wkbLinearRing) ring.AddPoint(10.0, 10.0) ring.AddPoint(10.0, 110.0) ring.AddPoint(110.0, 110.0) ring.AddPoint(110.0, 10.0) ring.AddPoint(10.0, 10.0) poly = ogr.Geometry(ogr.wkbPolygon) poly.AddGeometry(ring) vector_feature_definition = vector_layer.GetLayerDefn() vector_feature = ogr.Feature(vector_feature_definition) vector_feature.SetGeometry(poly) vector_layer.CreateFeature(vector_feature) vector_layer.CreateField(ogr.FieldDefn("class", ogr.OFTInteger)) feature = ogr.Feature(vector_layer.GetLayerDefn()) feature.SetField("class", 3) vector_data_source.FlushCache() self.vectors.append(vector_data_source) # Check this is the right thing to be saving here self.vector_paths.append(vector_file)
Example #3
Source File: functions.py From hants with Apache License 2.0 | 5 votes |
def Add_Field(input_lyr, field_name, ogr_field_type): """ Add a field to a layer using the following ogr field types: 0 = ogr.OFTInteger 1 = ogr.OFTIntegerList 2 = ogr.OFTReal 3 = ogr.OFTRealList 4 = ogr.OFTString 5 = ogr.OFTStringList 6 = ogr.OFTWideString 7 = ogr.OFTWideStringList 8 = ogr.OFTBinary 9 = ogr.OFTDate 10 = ogr.OFTTime 11 = ogr.OFTDateTime """ # List fields fields_ls = List_Fields(input_lyr) # Check if field exist if field_name in fields_ls: raise Exception('Field: "{0}" already exists'.format(field_name)) # Create field inp_field = ogr.FieldDefn(field_name, ogr_field_type) input_lyr.CreateField(inp_field) return inp_field
Example #4
Source File: functions.py From wa with Apache License 2.0 | 5 votes |
def Add_Field(input_lyr, field_name, ogr_field_type): """ Add a field to a layer using the following ogr field types: 0 = ogr.OFTInteger 1 = ogr.OFTIntegerList 2 = ogr.OFTReal 3 = ogr.OFTRealList 4 = ogr.OFTString 5 = ogr.OFTStringList 6 = ogr.OFTWideString 7 = ogr.OFTWideStringList 8 = ogr.OFTBinary 9 = ogr.OFTDate 10 = ogr.OFTTime 11 = ogr.OFTDateTime """ # List fields fields_ls = List_Fields(input_lyr) # Check if field exist if field_name in fields_ls: raise Exception('Field: "{0}" already exists'.format(field_name)) # Create field inp_field = ogr.FieldDefn(field_name, ogr_field_type) input_lyr.CreateField(inp_field) return inp_field
Example #5
Source File: io.py From spandex with BSD 3-Clause "New" or "Revised" License | 4 votes |
def dbf_to_df(path): """ Return DataFrame from attributes stored in dBase/xBase format. Uses OGR's ESRI Shapefile driver to read records from the file. Parameters ---------- path : str File path to the dBase/xBase file. Returns ------- df : pandas.DataFrame """ import ogr # Open the file and collect information on fields. dbf = ogr.Open(path) table = dbf.GetLayer() header = table.GetLayerDefn() ncolumns = header.GetFieldCount() column_names = [header.GetFieldDefn(i).GetName() for i in range(ncolumns)] column_types = [header.GetFieldDefn(i).GetType() for i in range(ncolumns)] def read(row, i): """Return i-th field of a record.""" # For performance, use the appropriate field type function. fld_type = column_types[i] if fld_type == ogr.OFTInteger: return row.GetFieldAsInteger(i) elif fld_type == ogr.OFTReal: return row.GetFieldAsDouble(i) elif fld_type == ogr.OFTStringList: return row.GetFieldAsStringList(i) elif fld_type == ogr.OFTIntegerList: return row.GetFieldAsIntegerList(i) elif fld_type == ogr.OFTRealList: return row.GetFieldAsDoubleList(i) else: return row.GetFieldAsString(i) # Represent records with memory-efficient generators. values = lambda row: (read(row, i) for i in range(ncolumns)) records = (values(row) for row in table) df = pd.DataFrame.from_records(records, columns=column_names, coerce_float=False) return df