当前位置: 首页>>代码示例>>Python>>正文


Python geoalchemy2.Geometry方法代码示例

本文整理汇总了Python中geoalchemy2.Geometry方法的典型用法代码示例。如果您正苦于以下问题:Python geoalchemy2.Geometry方法的具体用法?Python geoalchemy2.Geometry怎么用?Python geoalchemy2.Geometry使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在geoalchemy2的用法示例。


在下文中一共展示了geoalchemy2.Geometry方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: ga_geometry

# 需要导入模块: import geoalchemy2 [as 别名]
# 或者: from geoalchemy2 import Geometry [as 别名]
def ga_geometry(_, gatype, nullable=True):
        t = gatype.geometry_type
        if t == 'POINT':
            return dt.Point(nullable=nullable)
        if t == 'LINESTRING':
            return dt.LineString(nullable=nullable)
        if t == 'POLYGON':
            return dt.Polygon(nullable=nullable)
        if t == 'MULTILINESTRING':
            return dt.MultiLineString(nullable=nullable)
        if t == 'MULTIPOINT':
            return dt.MultiPoint(nullable=nullable)
        if t == 'MULTIPOLYGON':
            return dt.MultiPolygon(nullable=nullable)
        if t == 'GEOMETRY':
            return dt.Geometry(nullable=nullable)
        else:
            raise ValueError("Unrecognized geometry type: {}".format(t)) 
开发者ID:ibis-project,项目名称:ibis,代码行数:20,代码来源:alchemy.py

示例2: oql_for_chunk

# 需要导入模块: import geoalchemy2 [as 别名]
# 或者: from geoalchemy2 import Geometry [as 别名]
def oql_for_chunk(self, chunk, include_self=False, skip=None):
        skip = set(skip or [])
        q = self.items.filter(cast(Item.location, Geometry).contained(envelope(chunk)))

        tags = set()
        for item in q:
            tags |= set(item.tags)
        tags.difference_update(skip_tags)
        tags.difference_update(skip)
        tags = matcher.simplify_tags(tags)
        if not(tags):
            print('no tags, skipping')
            return

        ymin, ymax, xmin, xmax = chunk
        bbox = '{:f},{:f},{:f},{:f}'.format(ymin, xmin, ymax, xmax)

        oql = overpass.oql_for_area(self.overpass_type,
                                    self.osm_id,
                                    tags,
                                    bbox, None,
                                    include_self=include_self)
        return oql 
开发者ID:EdwardBetts,项目名称:osm-wikidata,代码行数:25,代码来源:place.py

示例3: setup_spatial_table

# 需要导入模块: import geoalchemy2 [as 别名]
# 或者: from geoalchemy2 import Geometry [as 别名]
def setup_spatial_table(package_extent_class, db_srid=None):

    if legacy_geoalchemy:

        package_extent_table = Table(
            'package_extent', meta.metadata,
            Column('package_id', types.UnicodeText, primary_key=True),
            GeometryExtensionColumn('the_geom', Geometry(2, srid=db_srid))
        )

        meta.mapper(
            package_extent_class,
            package_extent_table,
            properties={'the_geom':
                        GeometryColumn(package_extent_table.c.the_geom,
                                       comparator=PGComparator)}
        )

        GeometryDDL(package_extent_table)
    else:

        # PostGIS 1.5 requires management=True when defining the Geometry
        # field
        management = (postgis_version()[:1] == '1')

        package_extent_table = Table(
            'package_extent', meta.metadata,
            Column('package_id', types.UnicodeText, primary_key=True),
            Column('the_geom', Geometry('GEOMETRY', srid=db_srid,
                                        management=management)),
        )

        meta.mapper(package_extent_class, package_extent_table)

    return package_extent_table 
开发者ID:italia,项目名称:daf-recipes,代码行数:37,代码来源:geoalchemy_common.py

示例4: add_geometry_column

# 需要导入模块: import geoalchemy2 [as 别名]
# 或者: from geoalchemy2 import Geometry [as 别名]
def add_geometry_column(cls):
        if not hasattr(cls, 'geom'):
            cls.geom = Column(Geometry(geometry_type='POINT', srid=config.SRID)) 
开发者ID:OpenTransitTools,项目名称:gtfsdb,代码行数:5,代码来源:shape.py

示例5: add_geometry_column

# 需要导入模块: import geoalchemy2 [as 别名]
# 或者: from geoalchemy2 import Geometry [as 别名]
def add_geometry_column(cls):
        if not hasattr(cls, 'geom'):
            from geoalchemy2 import Geometry
            cls.geom = Column(Geometry(geometry_type='POINT', srid=config.SRID)) 
开发者ID:OpenTransitTools,项目名称:gtfsdb,代码行数:6,代码来源:stop_base.py

示例6: add_geometry_column

# 需要导入模块: import geoalchemy2 [as 别名]
# 或者: from geoalchemy2 import Geometry [as 别名]
def add_geometry_column(cls):
        if not hasattr(cls, 'geom'):
            from geoalchemy2 import Geometry
            cls.geom = deferred(Column(Geometry('MULTILINESTRING'))) 
开发者ID:OpenTransitTools,项目名称:gtfsdb,代码行数:6,代码来源:route.py

示例7: add_geometry_column

# 需要导入模块: import geoalchemy2 [as 别名]
# 或者: from geoalchemy2 import Geometry [as 别名]
def add_geometry_column(cls):
        if not hasattr(cls, 'geom'):
            cls.geom = deferred(Column(Geometry(geometry_type='LINESTRING', srid=config.SRID))) 
开发者ID:OpenTransitTools,项目名称:gtfsdb,代码行数:5,代码来源:pattern_base.py

示例8: show_polygons

# 需要导入模块: import geoalchemy2 [as 别名]
# 或者: from geoalchemy2 import Geometry [as 别名]
def show_polygons(place_identifier):
    place = get_place(place_identifier)
    num = 0
    for chunk in place.polygon_chunk(size=64):
        num += 1
        print(chunk)

    print()
    print(num)

    return
    num = '(-?[0-9.]+)'
    re_box = re.compile(f'^BOX\({num} {num},{num} {num}\)$')

    # select ST_Dump(geom::geometry) as poly from place where osm_id=1543125
    stmt = (database.session.query(func.ST_Dump(Place.geom.cast(Geometry())).label('x'))
                            .filter_by(place_id=place.place_id)
                            .subquery())

    q = database.session.query(stmt.c.x.path[1],
                               func.ST_Area(stmt.c.x.geom.cast(Geography)) / (1000 * 1000),
                               func.Box2D(stmt.c.x.geom))
    print(q)

    for num, area, box2d in q:
        # west, south, east, north
        # BOX(135.8536855 20.2145811,136.3224209 20.6291059)

        size = wikidata_chunk_size(area)
        west, south, east, north = map(float, re_box.match(box2d).groups())
        bbox = (south, north, west, east)

        # print((num, area, size, box2d))

        for chunk in chunk_n(bbox, size):
            print(chunk) 
开发者ID:EdwardBetts,项目名称:osm-wikidata,代码行数:38,代码来源:cli.py

示例9: polygon_chunk

# 需要导入模块: import geoalchemy2 [as 别名]
# 或者: from geoalchemy2 import Geometry [as 别名]
def polygon_chunk(self, size=64):
        stmt = (session.query(func.ST_Dump(Place.geom.cast(Geometry())).label('x'))
                       .filter_by(place_id=self.place_id)
                       .subquery())

        q = session.query(stmt.c.x.path[1],
                          func.ST_Area(stmt.c.x.geom.cast(Geography)) / (1000 * 1000),
                          func.Box2D(stmt.c.x.geom))

        for num, area, box2d in q:
            chunk_size = utils.calc_chunk_size(area, size=size)
            west, south, east, north = map(float, re_box.match(box2d).groups())
            for chunk in bbox_chunk((south, north, west, east), chunk_size):
                yield chunk 
开发者ID:EdwardBetts,项目名称:osm-wikidata,代码行数:16,代码来源:place.py

示例10: geometry_updater

# 需要导入模块: import geoalchemy2 [as 别名]
# 或者: from geoalchemy2 import Geometry [as 别名]
def geometry_updater(column, table, columns):
    """
    Updater for a geometry column.
    :param column: Geometry column
    :type column: GeometryColumn
    :param columns: Existing column names in the database for the given table.
    :type columns: list
    """
    geom_type = column.geometry_type()

    return _update_col(column, table, Geometry(geometry_type=geom_type,
                                               srid=column.srid),
                       columns) 
开发者ID:gltn,项目名称:stdm,代码行数:15,代码来源:column_updaters.py

示例11: srid_equality

# 需要导入模块: import geoalchemy2 [as 别名]
# 或者: from geoalchemy2 import Geometry [as 别名]
def srid_equality(tables):
    """
    Check whether there is only one projection in list of tables.

    Parameters
    ----------
    tables: iterable
        List of table ORM classes to inspect geometry columns.

    Returns
    -------
    unique: boolean

    """
    # Iterate over all columns to build set of SRIDs.
    srids = set()
    for table in tables:
        for c in table.__table__.columns:
            if isinstance(c.type, Geometry):
                # Column is geometry column.
                srids.add(c.type.srid)

    # Projection is unique if set has single SRID.
    assert len(srids) > 0
    if len(srids) == 1:
        return True
    else:
        return False 
开发者ID:UDST,项目名称:spandex,代码行数:30,代码来源:spatialtoolz.py

示例12: _to_sqla_type

# 需要导入模块: import geoalchemy2 [as 别名]
# 或者: from geoalchemy2 import Geometry [as 别名]
def _to_sqla_type(itype, type_map=None):
    if type_map is None:
        type_map = _ibis_type_to_sqla
    if isinstance(itype, dt.Decimal):
        return sa.types.NUMERIC(itype.precision, itype.scale)
    elif isinstance(itype, dt.Date):
        return sa.Date()
    elif isinstance(itype, dt.Timestamp):
        # SQLAlchemy DateTimes do not store the timezone, just whether the db
        # supports timezones.
        return sa.TIMESTAMP(bool(itype.timezone))
    elif isinstance(itype, dt.Array):
        ibis_type = itype.value_type
        if not isinstance(ibis_type, (dt.Primitive, dt.String)):
            raise TypeError(
                'Type {} is not a primitive type or string type'.format(
                    ibis_type
                )
            )
        return sa.ARRAY(_to_sqla_type(ibis_type, type_map=type_map))
    elif geospatial_supported and isinstance(itype, dt.GeoSpatial):
        if itype.geotype == 'geometry':
            return ga.Geometry
        elif itype.geotype == 'geography':
            return ga.Geography
        else:
            return ga.types._GISType
    else:
        return type_map[type(itype)] 
开发者ID:ibis-project,项目名称:ibis,代码行数:31,代码来源:alchemy.py

示例13: trim

# 需要导入模块: import geoalchemy2 [as 别名]
# 或者: from geoalchemy2 import Geometry [as 别名]
def trim(target_col, trim_col):
    """
    Trim target geometry by removing intersection with a trim column.

    Parameters
    ----------
    target_col : sqlalchemy.orm.attributes.InstrumentedAttribute
        Column ORM object to trim.
    trim_col : sqlalchemy.orm.attributes.InstrumentedAttribute
        Column ORM object to trim target column with.

    Returns
    -------
    None

    """
    # TODO: Aggregate multiple rows in trim_col.
    # Needs testing to make sure that ST_Difference can handle MultiPolygons
    # without data loss.
    with db.session() as sess:
        data_type = target_col.property.columns[0].type
        geom_type = data_type.geometry_type
        if geom_type.lower() == "multipolygon":
            # ST_Difference outputs Polygon, not MultiPolygon.
            # Temporarily change the geometry data type to generic Geometry.
            column_name = target_col.name
            table_name = target_col.parent.tables[0].name
            schema_name = target_col.parent.tables[0].schema
            srid = data_type.srid
            sess.execute("""
                ALTER TABLE {schema}.{table} ALTER COLUMN {column}
                SET DATA TYPE geometry(Geometry, {srid});
            """.format(
                schema=schema_name, table=table_name, column=column_name,
                srid=srid)
            )

        # Update column value with ST_Difference if ST_Intersects.
        table = target_col.parent
        sess.query(table).filter(
            target_col.ST_Intersects(trim_col)
        ).update(
            {target_col: target_col.ST_Difference(trim_col)},
            synchronize_session=False
        )

        if geom_type.lower() == "multipolygon":
            # Coerce the geometry data type back to MultiPolygon.
            sess.execute("""
                ALTER TABLE {schema}.{table} ALTER COLUMN {column}
                SET DATA TYPE geometry(MultiPolygon, {srid})
                USING ST_Multi(geom);
            """.format(
                schema=schema_name, table=table_name, column=column_name,
                srid=srid)
            ) 
开发者ID:UDST,项目名称:spandex,代码行数:58,代码来源:spatialtoolz.py

示例14: conform_srids

# 需要导入模块: import geoalchemy2 [as 别名]
# 或者: from geoalchemy2 import Geometry [as 别名]
def conform_srids(srid, schema=None, fix=False):
    """
    Reproject all non-conforming geometry columns into the specified SRID.

    Parameters
    ----------
    srid : int
        Spatial Reference System Identifier (SRID).
    schema : schema class, optional
        If schema is specified, only SRIDs within the specified schema
        are conformed.
    fix : bool, optional
        Whether to report and attempt to fix invalid geometries.

    Returns
    -------
    None

    """
    # Iterate over all columns. Reproject geometry columns with SRIDs
    # that differ from project SRID.
    for schema_name, schema_obj in db.tables.__dict__.items():
        if not schema_name.startswith('_'):
            if not schema or schema_name == schema.__name__:
                for table_name, table in schema_obj.__dict__.items():
                    if not table_name.startswith('_'):
                        for c in table.__table__.columns:
                            if isinstance(c.type, Geometry):
                                # Fix geometry if asked to do so.
                                if fix:
                                    if c.name == 'geom':
                                        invalid_df = geom_invalid(table)
                                        if not invalid_df.empty:
                                            logger.warn(invalid_df)
                                            validate(table=table)
                                    else:
                                        validate(column=getattr(table,
                                                                c.name))

                                # Reproject if SRID differs from project SRID.
                                current_srid = c.type.srid
                                if srid != current_srid:
                                    column = getattr(table, c.name)
                                    reproject(srid, table, column) 
开发者ID:UDST,项目名称:spandex,代码行数:46,代码来源:spatialtoolz.py


注:本文中的geoalchemy2.Geometry方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。