IdaGeoDataFrame

An IdaGeoDataFrame is a reference to a spatial table in a remote instance of dashDB.

The most important property of an IdaGeoDataFrame is that it always has a reference to one IdaGeoSeries column that holds a special status. This IdaGeoSeries is referred to as the IdaGeoDataFrame‘s “geometry”. When a spatial method is applied to an IdaGeoDataFrame (or a spatial attribute like area is called), this commands will always act on the “geometry” attribute.

The “geometry” attribute – no matter its name – can be accessed through the geometry attribute of an IdaGeoDataFrame.

Open an IdaGeoDataFrame

class ibmdbpy.geoFrame.IdaGeoDataFrame(idadb, tablename, indexer=None, geometry=None)[source]

An IdaGeoDataFrame container inherits from IdaDataFrame.

It has a property called “geometry” which refers to a column with geometry type. It is set as a string with a column name, either at instantiation time or with the set_geometry() method.

If the “geometry” property is set, when calling a geospatial method from IdaDataFrame the method will be carried on the column this property refers to.

The property “geometry” returns an IdaGeoSeries.

See IdaDataFrame. See IdaGeoSeries.

Examples

>>> idageodf = IdaGeoDataFrame(idadb, 'SAMPLES.GEO_COUNTY',
indexer='OBJECTID')
>>> idageodf.dtypes
                 TYPENAME
OBJECTID          INTEGER
SHAPE     ST_MULTIPOLYGON
STATEFP           VARCHAR
COUNTYFP          VARCHAR
COUNTYNS          VARCHAR
NAME              VARCHAR
GEOID             VARCHAR
NAMELSAD          VARCHAR
LSAD              VARCHAR
CLASSFP           VARCHAR
MTFCC             VARCHAR
CSAFP             VARCHAR
CBSAFP            VARCHAR
METDIVFP          VARCHAR
FUNCSTAT          VARCHAR
ALAND             DECIMAL
AWATER            DECIMAL
INTPTLAT          VARCHAR
INTPTLON          VARCHAR
>>> idageodf[['NAME', 'SHAPE']].head()
       NAME                                              SHAPE
0    Becker  MULTIPOLYGON (((-95.1637185512 46.7176480983, ...
1  Jim Hogg  MULTIPOLYGON (((-98.9542377853 26.7856984795, ...
2     Henry  MULTIPOLYGON (((-88.0532984194 36.4970648458, ...
3     Keith  MULTIPOLYGON (((-102.0517705602 41.0038968011,...
4   Clinton  MULTIPOLYGON (((-94.2059683962 39.7458481141, ...
>>> idageodf.geometry
AttributeError: Geometry property has not been set yet. Use set_geometry
method to set it.
>>> idageodf.set_geometry('SHAPE')
>>> idageodf.geometry.column
'SHAPE'
>>> type(idageodf.geometry)
<class 'ibmdbpy.geoSeries.IdaGeoSeries'>
>>> idageoseries = idageodf.geometry    
>>> idageoseries.head()
0    MULTIPOLYGON (((-95.1637185512 46.7176480983, ...
1    MULTIPOLYGON (((-98.9542377853 26.7856984795, ...
2    MULTIPOLYGON (((-88.0532984194 36.4970648458, ...
3    MULTIPOLYGON (((-102.0517705602 41.0038968011,...
4    MULTIPOLYGON (((-94.2059683962 39.7458481141, ...
Name: SHAPE, dtype: object
>>> idageodf['County area'] = idageodf.area(unit='mile')
>>> counties_with_areas = idageodf[['NAME', 'SHAPE', 'County area']]
>>> counties_with_areas.dtypes
                    TYPENAME
NAME                 VARCHAR
SHAPE        ST_MULTIPOLYGON
County area           DOUBLE
>>> counties_with_areas.head()
        NAME                                             SHAPE  County area
0     Menard  MULTIPOLYGON (((-99.4847630885 30.940610279, ...   902.281540
1      Boone  MULTIPOLYGON (((-88.7764991497 42.491919892, ...   282.045087
2  Ochiltree  MULTIPOLYGON (((-100.5467326897 36.056542135,...   918.188142
3    Sharkey  MULTIPOLYGON (((-90.9143429922 33.007703026, ...   435.548518
4    Audubon  MULTIPOLYGON (((-94.7006367168 41.504155369, ...   444.827726
__init__(idadb, tablename, indexer=None, geometry=None)[source]

Constructor for IdaGeoDataFrame objects. See IdaDataFrame.__init__ documentation.

Parameters:

geometry : str, optional

Column name to set the “geometry” property of the IdaGeoDataFrame. The column must have geometry type.

Attributes

_geometry_colname (str) Name of the column that “geometry” property refers to. This attribute must be set through the set_geometry() method.
geometry (IdaGeoSeries) The column referenced by _geometry_colname attribute.

Set geometry

IdaGeoDataFrame.set_geometry(column_name)[source]

Receives a column name to set as the “geometry” column of the IdaDataFrame.

Raises:

KeyError

If the column is not present in the IdaGeoDataFrame.

TypeError

If the column doesn’t have geometry type.

Create from an IdaDataFrame

classmethod IdaGeoDataFrame.from_IdaDataFrame(idadf, geometry=None)[source]

Creates an IdaGeoDataFrame from an IdaDataFrame.

Parameters:

geometry : str, optional

Column name to set the “geometry” property of the IdaGeoDataFrame. The column must have geometry type.

Raises:

TypeError

If idadf is not an IdaDataFrame.

Get the geometry attribute

IdaGeoDataFrame.geometry()

Returns an IdaGeoSeries with the column whose name is stored in _geometry_colname attribute.

The setter calls the set_geometry() method.

Returns:

IdaGeoSeries

Raises:

AttributeError

If the property has not been set yet.

Geospatial Methods that return an IdaGeoDataFrame

Some geospatial methods operate on two IdaGeoDataFrames to return a result as a boolean or a new geometry. Such methods can be accessed with the IdaGeoDataFrame object to return a new IdaGeoDataFrame with three columns respectively, indexer of the first IdaGeoDataFrame with which the method is called, the indexer of the second IdaGeoDataFrame which is passed as an argument to the method and a third column which contains the result of the geometric operation between the geometry columns of the first and second IdaGeoDataFrames.

Contains

IdaGeoDataFrame.contains(ida2)[source]

Valid types for the column in the calling IdaGeoDataFrame: ST_Geometry or one of its subtypes.

Returns an IdaGeoDataFrame of indices of the two input IdaGeoDataFrames and a result column with 1 or 0 depending upon whether the second geometry contains the first.

For None geometries the output is None.

Parameters:

ida2 : IdaGeoDataFrame

Name of the second IdaGeoDataFrame on which the function ST_EQUALS() will be invoked.

Returns:

Returns an IdaGeoDataFrame with three columns:

INDEXERIDA1 : indexer of the first IdaGeoSeries (None if not set),

INDEXERIDA2 : indexer of the second IdaGeoSeries (None if not set),

RESULT : the result of the operation

References

DB2 Spatial Extender ST_CONTAINS() function.

Examples

>>> idageodf_customer = IdaGeoDataFrame(idadb,'SAMPLES.GEO_CUSTOMER',indexer='OBJECTID')
>>> idageodf_customer.set_geometry('SHAPE')
>>> idageodf_county = IdaGeoDataFrame(idadb,'SAMPLES.GEO_COUNTY',indexer='OBJECTID')
>>> idageodf_county.set_geometry('SHAPE')
>>> ida1 = idageodf_customer[idageodf_customer['INSURANCE_VALUE']>250000]
>>> ida2 = idageodf_county[idageodf_county['NAME']=='Madison']
>>> result = ida2.contains(ida1)
>>> result[result['RESULT']==1].head()
INDEXERIDA1    INDEXERIDA2    RESULT
21473          134            1
21413          134            1
21414          134            1
21417          134            1
21419          134            1

Crosses

IdaGeoDataFrame.crosses(ida2)[source]

Valid types for the column in the calling IdaGeoDataFrame: ST_Geometry or one of its subtypes.

Returns an IdaGeoDataFrame of indices of the two input IdaGeoDataFrames and a result column with 1 or 0 depending upon whether the geometry of the first IdaGeoDataFrame crosses the second.

For None geometries the output is None.

Parameters:

ida2 : IdaGeoDataFrame

Name of the second IdaGeoDataFrame on which the function ST_EQUALS() will be invoked.

Returns:

Returns an IdaGeoDataFrame with three columns:

INDEXERIDA1 : indexer of the first IdaGeoSeries (None if not set),

INDEXERIDA2 : indexer of the second IdaGeoSeries (None if not set),

RESULT : the result of the operation

See also

linear_units
list of valid units.

References

DB2 Spatial Extender ST_CROSSES() function.

Examples

>>> counties = IdaGeoDataFrame(idadb,'SAMPLES.GEO_COUNTY',indexer='OBJECTID')
>>> counties.set_geometry('SHAPE')
>>> ida1 = counties[counties['NAME'] == 'Austin']
>>> ida2 = counties[counties['NAME'] == 'Kent']
>>> result = ida1.crosses(ida2)
>>> result.head()
INDEXERIDA1  INDEXERIDA2  RESULT
2            163          0
2            1840         0
2            109          0

Difference

IdaGeoDataFrame.difference(ida2)[source]

This method takes a second IdaGeoDataFrame an an input and returns the difference of the geometries from both IdaGeoDataFrames as a new geometry stored in the RESULT column of the resulting IdaGeoDataFrame.

For None geometries the output is None. For empty geometries the output is None.

Parameters:

ida2 : IdaGeoDataFrame

Name of the second IdaGeoDataFrame on which the function ST_EQUALS() will be invoked.

Returns:

Returns an IdaGeoDataFrame with three columns:

INDEXERIDA1 : indexer of the first IdaGeoSeries (None if not set),

INDEXERIDA2 : indexer of the second IdaGeoSeries (None if not set),

RESULT : the result of the operation

References

DB2 Spatial Extender ST_Difference() function.

Examples

>>> counties = IdaGeoDataFrame(idadb,'SAMPLES.GEO_COUNTY',indexer='OBJECTID')
>>> counties.set_geometry('SHAPE')
>>> ida1 = counties[counties['NAME'] == 'Austin']
>>> ida2 = counties[counties['NAME'] == 'Kent']
>>> result = ida1.difference(ida2)
>>> result.head()
INDEXERIDA1  INDEXERIDA2  RESULT
2            163          POLYGON ((-96.6219873342 30.0442882117, -96.61...
2            1840         POLYGON ((-96.6219873342 30.0442882117, -96.61...
2            109          POLYGON ((-96.6219873342 30.0442882117, -96.61...

Disjoint

IdaGeoDataFrame.disjoint(ida2)[source]

Valid types for the column in the calling IdaGeoDataFrame: ST_Geometry or one of its subtypes.

Returns an IdaGeoDataFrame of indices of the two input IdaGeoDataFrames and a result column with 1 or 0 depending upon whether the geometries in the input dataframes are disjoint.

For None geometries the output is None.

Parameters:

ida2 : IdaGeoDataFrame

Name of the second IdaGeoDataFrame on which the function ST_EQUALS() will be invoked.

Returns:

Returns an IdaGeoDataFrame with three columns:

INDEXERIDA1 : indexer of the first IdaGeoSeries (None if not set),

INDEXERIDA2 : indexer of the second IdaGeoSeries (None if not set),

RESULT : the result of the operation

References

DB2 Spatial Extender ST_DISJOINT() function.

Examples

>>> counties = IdaGeoDataFrame(idadb,'SAMPLES.GEO_COUNTY',indexer='OBJECTID')
>>> counties.set_geometry('SHAPE')
>>> ida1 = counties[counties['NAME'] == 'Austin']
>>> ida2 = counties[counties['NAME'] == 'Kent']
>>> result = ida1.disjoint(ida2)
>>> result.head()
INDEXERIDA1  INDEXERIDA2  RESULT
2            163          1
2            1840         1
2            109          1

Distance

IdaGeoDataFrame.distance(ida2, unit=None)[source]

Valid types for the column in the calling IdaGeoDataFrame: ST_Geometry or one of its subtypes.

Returns an IdaGeoDataFrame of indices of the two input IdaGeoDataFrames and a result column with a numeric value which is the geographic distance measured between the geometries of the input IdaGeoDataFrames.

For None geometries the output is None.

Parameters:

ida2 : IdaGeoDataFrame

Name of the second IdaGeoDataFrame on which the function ST_EQUALS() will be invoked.

unit : str, optional

Name of the unit, it is case-insensitive. If omitted, the following rules are used:

  • If geometry is in a projected or geocentric coordinate

system, the linear unit associated with this coordinate system is used. * If geometry is in a geographic coordinate system, the angular unit associated with this coordinate system is used.

Returns:

Returns an IdaGeoDataFrame with three columns:

INDEXERIDA1 : indexer of the first IdaGeoSeries (None if not set),

INDEXERIDA2 : indexer of the second IdaGeoSeries (None if not set),

RESULT : the result of the operation

References

DB2 Spatial Extender ST_DISTANCE() function.

Examples

>>> counties = IdaGeoDataFrame(idadb,'SAMPLES.GEO_COUNTY',indexer='OBJECTID')
>>> counties.set_geometry('SHAPE')
>>> ida1 = counties[counties['NAME'] == 'Austin']
>>> ida2 = counties[counties['NAME'] == 'Kent']
>>> result = ida1.distance(ida2,unit = 'KILOMETER')
>>> result.head()
INDEXERIDA1  INDEXERIDA2  RESULT
2            163          26.918942
2            1840         4.868971
2            109          16.387094

Equals

IdaGeoDataFrame.equals(ida2)[source]

Valid types for the column in the calling IdaGeoDataFrame: ST_Geometry or one of its subtypes.

Returns an IdaGeoDataFrame of indices of the two input IdaGeoDataFrames and a result column with 1 or 0 depending upon whether the geometry of the first IdaGeoDataFrame crosses the second.

For None geometries the output is None.

Parameters:

ida2 : IdaGeoDataFrame

Name of the second IdaGeoDataFrame on which the function ST_EQUALS() will be invoked.

Returns:

Returns an IdaGeoDataFrame with three columns:

INDEXERIDA1 : indexer of the first IdaGeoSeries (None if not set),

INDEXERIDA2 : indexer of the second IdaGeoSeries (None if not set),

RESULT : the result of the operation

References

DB2 Spatial Extender ST_CROSSES() function.

Examples

>>> counties = IdaGeoDataFrame(idadb,'SAMPLES.GEO_COUNTY',indexer='OBJECTID')
>>> counties.set_geometry('SHAPE')
>>> ida1 = counties[counties['NAME'] == 'Austin']
>>> ida2 = counties[counties['NAME'] == 'Kent']
>>> result = ida1.equals(ida2)
>>> result.head()
INDEXERIDA1  INDEXERIDA2  RESULT
2            163          0
2            1840         0
2            109          0

Intersection

IdaGeoDataFrame.intersection(ida2)[source]

This method takes a second IdaGeoDataFrame an an input and returns the intersection of the geometries from both IdaGeoDataFrames as a new geometry stored in the RESULT column of the resulting IdaGeoDataFrame.

For None geometries the output is None. For empty geometries the output is POINT EMPTY.

Parameters:

ida2 : IdaGeoDataFrame

Name of the second IdaGeoDataFrame on which the function ST_EQUALS() will be invoked.

Returns:

Returns an IdaGeoDataFrame with three columns:

INDEXERIDA1 : indexer of the first IdaGeoSeries (None if not set),

INDEXERIDA2 : indexer of the second IdaGeoSeries (None if not set),

RESULT : the result of the operation

References

DB2 Spatial Extender ST_Intersection() function.

Examples

>>> counties = IdaGeoDataFrame(idadb,'SAMPLES.GEO_COUNTY',indexer='OBJECTID')
>>> counties.set_geometry('SHAPE')
>>> ida1 = counties[counties['NAME'] == 'Austin']
>>> ida2 = counties[counties['NAME'] == 'Kent']
>>> result = ida1.intersection(ida2)
>>> result.head()
INDEXERIDA1  INDEXERIDA2  RESULT
2            163          POINT EMPTY
2            1840         POINT EMPTY
2            109          POINT EMPTY

Intersects

IdaGeoDataFrame.intersects(ida2)[source]

Valid types for the column in the calling IdaGeoDataFrame: ST_Geometry or one of its subtypes.

Returns an IdaGeoDataFrame of indices of the two input IdaGeoDataFrames and a result column with 1 or 0 depending upon whether the geometries of the input IdaGeoDataFrames intersect each other.

For None geometries the output is None.

Parameters:

ida2 : IdaGeoDataFrame

Name of the second IdaGeoDataFrame on which the function ST_EQUALS() will be invoked.

Returns:

Returns an IdaGeoDataFrame with three columns:

INDEXERIDA1 : indexer of the first IdaGeoSeries (None if not set),

INDEXERIDA2 : indexer of the second IdaGeoSeries (None if not set),

RESULT : the result of the operation

References

DB2 Spatial Extender ST_INTERSECTS() function.

Examples

>>> counties = IdaGeoDataFrame(idadb,'SAMPLES.GEO_COUNTY',indexer='OBJECTID')
>>> counties.set_geometry('SHAPE')
>>> ida1 = counties[counties['NAME'] == 'Austin']
>>> ida2 = counties[counties['NAME'] == 'Kent']
>>> result = ida1.intersects(ida2)
>>> result.head()
INDEXERIDA1  INDEXERIDA2  RESULT
2            163          0
2            1840         0
2            109          0

Mbr_Intersects

IdaGeoDataFrame.mbr_intersects(ida2)[source]

This method takes a second IdaGeoDataFrame an an input and checks if the Minimum Bounding rectangles of the geometries from both IdaGeoDataFrames intersect and stores the result as 0 or 1 in the RESULT column of the resulting IdaGeoDataFrame.

For None geometries the output is None. For empty geometries the output is None.

Parameters:

ida2 : IdaGeoDataFrame

Name of the second IdaGeoDataFrame on which the function ST_EQUALS() will be invoked.

Returns:

Returns an IdaGeoDataFrame with three columns:

INDEXERIDA1 : indexer of the first IdaGeoSeries (None if not set),

INDEXERIDA2 : indexer of the second IdaGeoSeries (None if not set),

RESULT : the result of the operation

References

DB2 Spatial Extender ST_MBRIntersects() function.

Examples

>>> counties = IdaGeoDataFrame(idadb,'SAMPLES.GEO_COUNTY',indexer='OBJECTID')
>>> counties.set_geometry('SHAPE')
>>> ida1 = counties[counties['NAME'] == 'Austin']
>>> ida2 = counties[counties['NAME'] == 'Kent']
>>> result = ida1.difference(ida2)
>>> result.head()
INDEXERIDA1  INDEXERIDA2  RESULT
2            163          0
2            1840         0
2            109          0

Overlaps

IdaGeoDataFrame.overlaps(ida2)[source]

Valid types for the column in the calling IdaGeoDataFrame: ST_Geometry or one of its subtypes.

Returns an IdaGeoDataFrame of indices of the two input IdaGeoDataFrames and a result column with 1 or 0 depending upon whether the geometries of the input IdaGeoDataFrames overlap each other.

For None geometries the output is None.

Parameters:

ida2 : IdaGeoDataFrame

Name of the second IdaGeoDataFrame on which the function ST_EQUALS() will be invoked.

Returns:

Returns an IdaGeoDataFrame with three columns:

INDEXERIDA1 : indexer of the first IdaGeoSeries (None if not set),

INDEXERIDA2 : indexer of the second IdaGeoSeries (None if not set),

RESULT : the result of the operation

References

DB2 Spatial Extender ST_OVERLAPS() function.

Examples

>>> counties = IdaGeoDataFrame(idadb,'SAMPLES.GEO_COUNTY',indexer='OBJECTID')
>>> counties.set_geometry('SHAPE')
>>> ida1 = counties[counties['NAME'] == 'Austin']
>>> ida2 = counties[counties['NAME'] == 'Kent']
>>> result = ida1.overlaps(ida2)
>>> result.head()
INDEXERIDA1  INDEXERIDA2  RESULT
2            163          0
2            1840         0
2            109          0

Touches

IdaGeoDataFrame.touches(ida2)[source]

Valid types for the column in the calling IdaGeoDataFrame: ST_Geometry or one of its subtypes.

Returns an IdaGeoDataFrame of indices of the two input IdaGeoDataFrames and a result column with 1 or 0 depending upon whether the boundary of the first geometry touches the second.

For None geometries the output is None.

Parameters:

ida2 : IdaGeoDataFrame

Name of the second IdaGeoDataFrame on which the function ST_EQUALS() will be invoked.

Returns:

Returns an IdaGeoDataFrame with three columns:

INDEXERIDA1 : indexer of the first IdaGeoSeries (None if not set),

INDEXERIDA2 : indexer of the second IdaGeoSeries (None if not set),

RESULT : the result of the operation

References

DB2 Spatial Extender ST_TOUCHES() function.

Examples

>>> counties = IdaGeoDataFrame(idadb,'SAMPLES.GEO_COUNTY',indexer='OBJECTID')
>>> counties.set_geometry('SHAPE')
>>> ida1 = counties[counties['NAME'] == 'Austin']
>>> ida2 = counties[counties['NAME'] == 'Kent']
>>> result = ida1.touches(ida2)
>>> result.head()
INDEXERIDA1  INDEXERIDA2  RESULT
2            163          0
2            1840         0
2            109          0

Union

IdaGeoDataFrame.union(ida2)[source]

This method takes a second IdaGeoDataFrame an an input and returns the union of the geometries from both IdaGeoDataFrames as a new geometry stored in the RESULT column of the resulting IdaGeoDataFrame.

For None geometries the output is None. For empty geometries the output is None.

Parameters:

ida2 : IdaGeoDataFrame

Name of the second IdaGeoDataFrame on which the function ST_EQUALS() will be invoked.

Returns:

Returns an IdaGeoDataFrame with three columns:

INDEXERIDA1 : indexer of the first IdaGeoSeries (None if not set),

INDEXERIDA2 : indexer of the second IdaGeoSeries (None if not set),

RESULT : the result of the operation

References

DB2 Spatial Extender ST_Union() function.

Examples

>>> counties = IdaGeoDataFrame(idadb,'SAMPLES.GEO_COUNTY',indexer='OBJECTID')
>>> counties.set_geometry('SHAPE')
>>> ida1 = counties[counties['NAME'] == 'Austin']
>>> ida2 = counties[counties['NAME'] == 'Kent']
>>> result = ida1.union(ida2)
>>> result.head()
INDEXERIDA1  INDEXERIDA2  RESULT
2            163          MULTIPOLYGON (((-96.6219873342 30.0442882117, ...
2            1840         MULTIPOLYGON (((-96.6219873342 30.0442882117, ...
2            109          MULTIPOLYGON (((-96.6219873342 30.0442882117, ..

Within

IdaGeoDataFrame.within(ida2)[source]

Valid types for the column in the calling IdaGeoDataFrame: ST_Geometry or one of its subtypes.

Returns an IdaGeoDataFrame of indices of the two input IdaGeoDataFrames and a result column with 1 or 0 depending upon whether the first geometry is inside the second.

For None geometries the output is None.

Parameters:

ida2 : IdaGeoDataFrame

Name of the second IdaGeoDataFrame on which the function ST_EQUALS() will be invoked.

Returns:

Returns an IdaGeoDataFrame with three columns:

INDEXERIDA1 : indexer of the first IdaGeoSeries (None if not set),

INDEXERIDA2 : indexer of the second IdaGeoSeries (None if not set),

RESULT : the result of the operation

References

DB2 Spatial Extender ST_WITHIN() function.

Examples

>>> idageodf_customer = IdaGeoDataFrame(idadb,'SAMPLES.GEO_CUSTOMER',indexer='OBJECTID')
>>> idageodf_customer.set_geometry('SHAPE')
>>> idageodf_county = IdaGeoDataFrame(idadb,'SAMPLES.GEO_COUNTY',indexer='OBJECTID')
>>> idageodf_county.set_geometry('SHAPE')
>>> ida1 = idageodf_customer[idageodf_customer['INSURANCE_VALUE']>250000]
>>> ida2 = idageodf_county[idageodf_county['NAME']=='Madison']
>>> result = ida1.within(ida2)
>>> result[result['RESULT']==1].head()
INDEXERIDA1    INDEXERIDA2    RESULT
134            21473          1
134            21413          1
134            21414          1
134            21417          1
134            21419          1