geoalchemy2

一、定義空間字段:

因?yàn)樵摪姹局С謩?chuàng)建Geography字段類型,因此創(chuàng)建空間字段不同于之前版本,采用了如下形式:

geom?=Column(Geometry('POLYGON’))

二、空間函數(shù)的使用:

需要注意的是所有函數(shù)都帶有ST_前綴,這也是為了與postgis寫(xiě)法一致.

函數(shù)的使用方法:

第一種是使用func,例如在orm中你可以:

Session.query(func.ST_Area(Lake.geom))或Session.query(Lake.geom.ST_Area())?進(jìn)行面積查詢

不使用orm你可以:

select([func.ST_Area(lake_table.c.geom)])

三、支持wkt和wkb格式

例如WKTElement('POINT(5 45)’)和WKTElement('POINT(5 45)',srid=4326)對(duì)應(yīng)著Point類型的Geometry,和postgis中的ST_GeomFromText效果相同。

同時(shí)支持與shapely庫(kù)的空間類型互相轉(zhuǎn)換,詳情請(qǐng)查閱geoalchemy2.shape.from_shape和geoalchemy2.shape.to_shape方法

空間函數(shù)整理:(谷歌機(jī)翻加上了自己的一點(diǎn)調(diào)整)

函數(shù)名 ?返回類型?

2.1?geometry訪問(wèn)相關(guān)

('ST_Envelope',types.Geometry,

?????'返回提供的geometry的外邊框,雙精度(float8)’)

????('ST_GeometryN',無(wú),

?????'如果幾何是``GEOMETRYCOLLECTION``,``(MULTI)POINT``,``(MULTI)LINESTRING``,``MULTICURVE``或``(MULTI)POLYGON``,``POLYHEDRALSURFACE``,則返回基于1的第N個(gè)幾何, 否則返回``None``。),

????('ST_GeometryType',無(wú),

?????'返回``ST_Geometry``返回值的幾何類型。'),

????('ST_IsValid',無(wú),

?????如果``ST_Geometry``返回的空間數(shù)據(jù)有效,則返回``True``。'),

????('ST_NPoints',無(wú),

?????'返回Geometry數(shù)據(jù)中的節(jié)點(diǎn)數(shù)。'),

????('ST_SRID',無(wú),

?????‘返回Geometry數(shù)據(jù)的SRID數(shù)值,該數(shù)值參考spatial_ref_sys表中的定義)

????('ST_X',無(wú),

? ? ?返回點(diǎn)的X坐標(biāo),如果不可用,則返回“無(wú)”。輸入必須是一個(gè)Point類型數(shù)據(jù)),

????('ST_Y',無(wú),返回點(diǎn)的Y坐標(biāo),如果不可用,則返回“無(wú)”。輸入必須是一個(gè)Point類型數(shù)據(jù))

????('ST_Z',無(wú),返回點(diǎn)的Z坐標(biāo),如果不可用,則返回“無(wú)”。輸入必須是一個(gè)Point類型數(shù)據(jù))

? ? 2.2 geometry編輯相關(guān)


????('ST_Transform',types.Geometry,

?????'返回一個(gè)新的幾何體,其坐標(biāo)轉(zhuǎn)換為輸入的SRID'),

? ? 2.3 geometry輸出


????('ST_AsBinary',無(wú),轉(zhuǎn)化成WKB),

????('ST_AsEWKB',無(wú),轉(zhuǎn)化成EWKB),

????('ST_AsTWKB',無(wú),轉(zhuǎn)化成TWKB),

????('ST_AsGeoJSON',無(wú),'將geometry轉(zhuǎn)化成GeoJSON元素返回。'),

????('ST_AsGML',無(wú),'將geometry轉(zhuǎn)化成GML版本2或3。'),

????('ST_AsKML',無(wú),

'將geometry轉(zhuǎn)化為KML元素返回。多個(gè)類型。默認(rèn)參數(shù):'version = 2,default precision= 15'),

????('ST_AsSVG',無(wú),

?????'返回輸入geometry或geography的SVG格式數(shù)據(jù)'),

????('ST_AsText',無(wú),返回輸入geometry的WKT格式,沒(méi)有SRID信息)

????('ST_AsEWKT',無(wú),

?????'返回輸入geometry的EWKT格式數(shù)據(jù),具有SRID信息。'),

? ? 2.4 空間關(guān)系和測(cè)量

('ST_Area',無(wú),如果是polygon或multi-polygon,則返回平面面積;對(duì)于geometry類型的面積單位取決于SRID。對(duì)于geography類型面積單位為平方米),

????('ST_Azimuth',無(wú),返回pointb和pointb之間的角度的弧度值,順時(shí)針計(jì)算,12 = 0; 3 = PI / 2; 6 = PI; 9 = 3PI / 2),

????('ST_Centroid',types.Geometry,返回geometry的幾何中心),

????('ST_Contains',無(wú),A是否包含B'),

????('ST_ContainsProperly',A是否完全包含B,不內(nèi)切),

????('ST_Covers',無(wú),A是否包含B,可以內(nèi)切,

????('ST_CoveredBy',沒(méi)有,B是否包含A),

????('ST_Crosses',無(wú),

?????如果提供的幾何有一些但不是全部,則返回``True``

?????'內(nèi)部點(diǎn)共同點(diǎn)。'),

????('ST_Disjoint',無(wú),

?????如果幾何不“空間相交”,則返回``True``??- 如果'

?????“他們不共享任何空間?!保?,

????('ST_Distance',無(wú),

?????'對(duì)于幾何類型返回二維笛卡爾最小距離'

?????'(基于空間參考)在投影單位中的兩個(gè)幾何之間。為''

?????'地理類型默認(rèn)返回'之間的球形最小距離'

?????'米的兩個(gè)地理位置。'),

????('ST_Distance_Sphere',無(wú),

?????'返回兩個(gè)lon / lat幾何之間的最小距離(以米為單位)。使用'

?????'球形地球,半徑6370986米。比...快 '

?????'``ST_Distance_Spheroid``,但不太準(zhǔn)確。 PostGIS版本'

?????'在1.5之前只實(shí)現(xiàn)積分。'),

????('ST_DFullyWithin',沒(méi)有,

?????'如果所有幾何都在指定的范圍內(nèi),則返回``True``

?????'彼此的距離')

'ST_DWithin',沒(méi)有,

?????如果空間圖形在另一個(gè)空間圖形指定的距離內(nèi),則返回True。單位視空間坐標(biāo)系而定,geography的單位為米。默認(rèn)為球面,柵格數(shù)據(jù)默認(rèn)為非球面

????('ST_Intersects',無(wú),

?????如果geometry/geography相交,則返回true。

????('ST_Length',無(wú),

?????'如果它是一個(gè)LINESTRING或MULTILINESTRING,則返回幾何的2d長(zhǎng)度。幾何以空間參考為單位,geography以米為單位(默認(rèn)球體)'),

????('ST_LineLocatePoint',無(wú),

?????'返回一個(gè)介于0和1之間的浮點(diǎn)數(shù),表示LineString上最接近給定Point的點(diǎn)的距離占LineString總長(zhǎng)的百分比),

????('ST_OrderingEquals',無(wú),

?????如果給定的幾何表示相同的幾何,則返回``True``

?????'和點(diǎn)的方向順序相同。'),

????('ST_Overlaps',無(wú),

?????如果Geometries共享空間,則返回``True``,是相同的'

?????'維度,但彼此不完全包含。'),

????('ST_Perimeter',無(wú),

?????'返回ST_Surface邊界的長(zhǎng)度測(cè)量值或'

?????'ST_MultiSurface幾何或地理。 (多邊形,多邊形)。 “

?????'幾何測(cè)量以空間參考為單位,地理是'

?????'米。'),

????('ST_Project',types.Geography,

?????'返回一個(gè)從起始點(diǎn)投射的``POINT``使用距離'

?????'米和軸承(方位角)以弧度表示。'),

????('ST_Relate',無(wú),

?????'如果此幾何與空間相關(guān)',則返回``True``

?????'另一個(gè)幾何,通過(guò)測(cè)試內(nèi)部之間的交叉點(diǎn),'

?????'由值指定的兩個(gè)幾何的邊界和外部'

?????'在intersectionMatrixPattern中。如果沒(méi)有intersectionMatrixPattern'

?????'傳入,然后返回最大的intersectionMatrixPattern'

?????'涉及兩種幾何形狀。'),

????('ST_Touches',無(wú),

?????如果幾何有至少一個(gè)共同點(diǎn),'返回``True``

?????'但他們的內(nèi)部不相交。'),

????('ST_Within',沒(méi)有,

?????'如果幾何A完全在幾何B'內(nèi),則返回``True``,

????#

????#幾何處理

????#

????('ST_Buffer',types.Geometry,

?????'對(duì)于幾何體:返回表示其所有點(diǎn)的幾何體'

?????'與此幾何的距離小于或等于距離。 “

?????'計(jì)算在此幾何的空間參照系中。\ n \ n'

?????'對(duì)于地理:使用平面變換包裝。介紹1.5'

?????'支持不同的端蓋和斜接設(shè)置來(lái)控制形狀。'),

????('ST_Difference',types.Geometry,

?????'返回表示幾何A的那部分的幾何'

?????'與幾何B不相交''),

????('ST_Dump',types.GeometryDump,

?????'返回一組geometry_dump(geom,path)行,組成''

?????'geometry g1。'),

????('ST_DumpPoints',types.GeometryDump,

?????'返回一組所有點(diǎn)的geometry_dump(geom,path)行'

?????'構(gòu)成一個(gè)幾何。'),

????('ST_Intersection',types.Geometry,

?????'返回表示geomA和'的共享部分的幾何

?????“geomB。地理位置實(shí)現(xiàn)了對(duì)幾何體的轉(zhuǎn)換'

?????'交叉點(diǎn)然后轉(zhuǎn)換回WGS84。'),

????('ST_LineMerge',types.Geometry,

?????'返回一個(gè)(一組)LineString(s)形成的縫合在一起'

?????'MULTILINESTRING的組成線工作。'),

????('ST_LineSubstring',types.Geometry,

?????'返回一個(gè)線串作為輸入的一個(gè)子串開(kāi)始和'

?????'以總共2d長(zhǎng)度的給定分?jǐn)?shù)結(jié)束。第二和第三'

?????'參數(shù)是介于0和1之間的float8值。這僅適用于'

?????“線串。要使用連續(xù)的MULTILINESTRING,請(qǐng)使用'

?????'與ST_LineMerge結(jié)合。'

?????“”

?????'如果\'開(kāi)始\'和\'結(jié)尾\'具有相同的值,這相當(dāng)于'

?????'到ST_LineInterpolatePoint。'),

????('ST_Union',types.Geometry,

?????'返回表示'的點(diǎn)集聯(lián)合的幾何'

?????'的幾何形狀。'),

????('ST_Simplify',types.Geometry,

?????'使用'返回給定幾何的“簡(jiǎn)化”版本

?????'Douglas-Peucker算法。'),

????#

????#Raster構(gòu)造函數(shù)

????#

????('ST_GeomFromText',types.Geometry,

?????'從OGC著名文本構(gòu)造一個(gè)PostGIS ST_Geometry對(duì)象'

?????'表示。’),

('ST_GeomFromEWKT',types.Geometry,

?????'從OGC Extended Well-Known構(gòu)造一個(gè)PostGIS ST_Geometry對(duì)象'

?????'text(EWKT)表示。'),

????('ST_GeomFromEWKB',types.Geometry,

?????'從OGC Extended Well-Known構(gòu)造一個(gè)PostGIS ST_Geometry對(duì)象'

?????'二進(jìn)制(EWKB)表示。'),

????('ST_GeogFromText',types.Geography,

?????'從眾所周知的文本中返回地理對(duì)象或擴(kuò)展眾所周知的'

?????'表示。'),

????('ST_AsRaster',types.Raster,

?????('將PostGIS幾何體轉(zhuǎn)換為PostGIS柵格。','RT_ST_AsRaster')),

????#

????#Raster訪問(wèn)者

????#

????('ST_Height',無(wú),

?????('返回柵格的高度,以像素為單位。','RT_ST_Height')),

????('ST_Width',無(wú),

?????('返回柵格的寬度,以像素為單位。','RT_ST_Width')),

????#

????#Raster Pixel Accessors和Setters

????#

????('ST_Value',無(wú),

?????('返回給定columnx,rowy pixel或at'中給定band的值

??????'一個(gè)特定的幾何點(diǎn)。樂(lè)隊(duì)編號(hào)從1開(kāi)始并假設(shè)為'

??????'如果沒(méi)有指定則為1。如果``exclude_nodata_value``設(shè)置為'

??????'``false``,然后所有像素都包含nodata像素被認(rèn)為是'

??????'相交并返回值。如果沒(méi)有傳遞``exclude_nodata_value``'

??????'然后從柵格的元數(shù)據(jù)中讀取它。','RT_ST_Value’))

翻譯不動(dòng)了,貼上原文:

('ST_Envelope', types.Geometry,

'Returns a geometry representing the double precision (float8) bounding'

'box of the supplied geometry.'),

('ST_GeometryN',None,

'Return the 1-based Nth geometry if the geometry is a '

'``GEOMETRYCOLLECTION``, ``(MULTI)POINT``, ``(MULTI)LINESTRING``, '

'``MULTICURVE`` or ``(MULTI)POLYGON``, ``POLYHEDRALSURFACE`` Otherwise, '

'return ``None``.'),

('ST_GeometryType',None,

'Return the geometry type of the ``ST_Geometry`` value.'),

('ST_IsValid',None,

'Returns ``True`` if the ``ST_Geometry`` is well formed.'),

('ST_NPoints',None,

'Return the number of points (vertices) in a geometry.'),

('ST_SRID',None,

'Returns the spatial reference identifier for the ``ST_Geometry`` as '

'defined in ``spatial_ref_sys`` table.'),

('ST_X',None,

'Return the X coordinate of the point, or ``None`` if not available. '

'Input must be a point.'),

('ST_Y',None,

'Return the Y coordinate of the point, or ``None`` if not available. '

'Input must be a point.'),

('ST_Z',None,

'Return the Z coordinate of the point, or ``None`` if not available. '

'Input must be a point.'),

#

# Geometry Editors

#

('ST_Transform', types.Geometry,

'Return a new geometry with its coordinates transformed to the SRID '

'referenced by the integer parameter.'),

#

# Geometry Outputs

#

('ST_AsBinary',None,

'Return the Well-Known Binary (WKB) representation of the geometry/'

'geography without SRID meta data.'),

('ST_AsEWKB',None,

'Return the Well-Known Binary (WKB) representation of the geometry/'

'geography with SRID meta data.'),

('ST_AsTWKB',None,

'Returns the geometry as TWKB, aka "Tiny Well-Known Binary"'),

('ST_AsGeoJSON',None,'Return the geometry as a GeoJSON element.'),

('ST_AsGML',None,'Return the geometry as a GML version 2 or 3 element.'),

('ST_AsKML',None,

'Return the geometry as a KML element. Several variants. Default '

'version=2, default precision=15'),

('ST_AsSVG',None,

'Returns a Geometry in SVG path data given a geometry or geography '

'object.'),

('ST_AsText',None,

'Return the Well-Known Text (WKT) representation of the geometry/'

'geography without SRID metadata.'),

('ST_AsEWKT',None,

'Return the Well-Known Text (WKT) representation of the geometry/'

'geography with SRID metadata.'),

#

# Spatial Relationships and Measurements

#

('ST_Area',None,

'Returns the area of the surface if it is a polygon or multi-polygon. '

'For ``geometry`` type area is in SRID units. For ``geography`` area is '

'in square meters.'),

('ST_Azimuth',None,

'Returns the angle in radians from the horizontal of the '

'vector defined by pointA and pointB. Angle is computed clockwise from '

'down-to-up: on the clock: 12=0; 3=PI/2; 6=PI; 9=3PI/2.'),

('ST_Centroid', types.Geometry,

'Returns the geometric center of a geometry.'),

('ST_Contains',None,

'Returns ``True`` if and only if no points of B lie in the exterior of '

'A, and at least one point of the interior of B lies in the interior '

'of A.'),

('ST_ContainsProperly',None,

'Returns ``True`` if B intersects the interior of A but not the boundary '

'(or exterior). A does not contain properly itself, but does contain '

'itself.'),

('ST_Covers',None,

'Returns ``True`` if no point in Geometry B is outside Geometry A'),

('ST_CoveredBy',None,

'Returns ``True`` if no point in Geometry/Geography A is outside Geometry'

'/Geography B'),

('ST_Crosses',None,

'Returns ``True`` if the supplied geometries have some, but not all, '

'interior points in common.'),

('ST_Disjoint',None,

'Returns ``True`` if the Geometries do not "spatially intersect" - if '

'they do not share any space together.'),

('ST_Distance',None,

'For geometry type Returns the 2-dimensional cartesian minimum distance '

'(based on spatial ref) between two geometries in projected units. For '

'geography type defaults to return spheroidal minimum distance between '

'two geographies in meters.'),

('ST_Distance_Sphere',None,

'Returns minimum distance in meters between two lon/lat geometries. Uses '

'a spherical earth and radius of 6370986 meters. Faster than '

'``ST_Distance_Spheroid``, but less accurate. PostGIS versions '

'prior to 1.5 only implemented for points.'),

('ST_DFullyWithin',None,

'Returns ``True`` if all of the geometries are within the specified '

'distance of one another'),

('ST_DWithin',None,

'Returns ``True`` if the geometries are within the specified distance of '

'one another. For geometry units are in those of spatial reference and '

'for geography units are in meters and measurement is defaulted to '

'``use_spheroid=True`` (measure around spheroid), for faster check, '

'``use_spheroid=False`` to measure along sphere.'),

('ST_Equals',None,

'Returns ``True`` if the given geometries represent the same geometry. '

'Directionality is ignored.'),

('ST_Intersects',None,

'Returns ``True`` if the Geometries/Geography "spatially intersect in '

'2D" - (share any portion of space) and ``False`` if they don\'t (they '

'are Disjoint). For geography -- tolerance is 0.00001 meters (so any '

'points that close are considered to intersect)'),

('ST_Length',None,

'Returns the 2d length of the geometry if it is a linestring or '

'multilinestring. geometry are in units of spatial reference and '

'geography are in meters (default spheroid)'),

('ST_LineLocatePoint',None,

'Returns a float between 0 and 1 representing the location of the '

'closest point on LineString to the given Point, as a fraction of '

'total 2d line length.'),

('ST_OrderingEquals',None,

'Returns ``True`` if the given geometries represent the same geometry '

'and points are in the same directional order.'),

('ST_Overlaps',None,

'Returns ``True`` if the Geometries share space, are of the same '

'dimension, but are not completely contained by each other.'),

('ST_Perimeter',None,

'Return the length measurement of the boundary of an ST_Surface or '

'ST_MultiSurface geometry or geography. (Polygon, Multipolygon). '

'geometry measurement is in units of spatial reference and geography is '

'in meters.'),

('ST_Project', types.Geography,

'Returns a ``POINT`` projected from a start point using a distance in '

'meters and bearing (azimuth) in radians.'),

('ST_Relate',None,

'Returns ``True`` if this Geometry is spatially related to '

'anotherGeometry, by testing for intersections between the Interior, '

'Boundary and Exterior of the two geometries as specified by the values '

'in the intersectionMatrixPattern. If no intersectionMatrixPattern is '

'passed in, then returns the maximum intersectionMatrixPattern that '

'relates the 2 geometries.'),

('ST_Touches',None,

'Returns ``True`` if the geometries have at least one point in common, '

'but their interiors do not intersect.'),

('ST_Within',None,

'Returns ``True`` if the geometry A is completely inside geometry B'),

#

# Geometry Processing

#

('ST_Buffer', types.Geometry,

'For geometry: Returns a geometry that represents all points whose '

'distance from this Geometry is less than or equal to distance. '

'Calculations are in the Spatial Reference System of this Geometry.\n\n'

'For geography: Uses a planar transform wrapper. Introduced in 1.5 '

'support for different end cap and mitre settings to control shape.'),

('ST_Difference', types.Geometry,

'Returns a geometry that represents that part of geometry A that does '

'not intersect with geometry B.'),

('ST_Dump', types.GeometryDump,

'Returns a set of geometry_dump (geom,path) rows, that make up a '

'geometry g1.'),

('ST_DumpPoints', types.GeometryDump,

'Returns a set of geometry_dump (geom,path) rows of all points that '

'make up a geometry.'),

('ST_Intersection', types.Geometry,

'Returns a geometry that represents the shared portion of geomA and '

'geomB. The geography implementation does a transform to geometry to do '

'the intersection and then transform back to WGS84.'),

('ST_LineMerge', types.Geometry,

'Returns a (set of) LineString(s) formed by sewing together the '

'constituent line work of a MULTILINESTRING.'),

('ST_LineSubstring', types.Geometry,

'Return a linestring being a substring of the input one starting and '

'ending at the given fractions of total 2d length. Second and third '

'arguments are float8 values between 0 and 1. This only works with '

'LINESTRINGs. To use with contiguous MULTILINESTRINGs use in '

'conjunction with ST_LineMerge.'

''

'If\'start\'and\'end\'have the same value this is equivalent '

'to ST_LineInterpolatePoint.'),

('ST_Union', types.Geometry,

'Returns a geometry that represents the point set union of the '

'Geometries.'),

('ST_Simplify', types.Geometry,

'Returns a "simplified" version of the given geometry using the '

'Douglas-Peucker algorithm.'),

#

# Raster Constructors

#

('ST_GeomFromText', types.Geometry,

'Constructs a PostGIS ST_Geometry object from the OGC Well-Known text '

'representation.'),

('ST_GeomFromEWKT', types.Geometry,

'Constructs a PostGIS ST_Geometry object from the OGC Extended Well-Known '

'text (EWKT) representation.'),

('ST_GeomFromEWKB', types.Geometry,

'Constructs a PostGIS ST_Geometry object from the OGC Extended Well-Known '

'binary (EWKB) representation.'),

('ST_GeogFromText', types.Geography,

'Returns a geography object from the well-known text or extended well-known '

'representation.'),

('ST_AsRaster', types.Raster,

('Converts a PostGIS geometry to a PostGIS raster.','RT_ST_AsRaster')),

#

# Raster Accessors

#

('ST_Height',None,

('Returns the height of the raster in pixels.','RT_ST_Height')),

('ST_Width',None,

('Returns the width of the raster in pixels.','RT_ST_Width')),

#

# Raster Pixel Accessors and Setters

#

('ST_Value',None,

('Returns the value of a given band in a given columnx, rowy pixel or at '

'a particular geometric point. Band numbers start at 1 and assumed to '

'be 1 if not specified. If ``exclude_nodata_value`` is set to '

'``false``, then all pixels include nodata pixels are considered to '

'intersect and return value. If ``exclude_nodata_value`` is not passed '

'in then reads it from metadata of raster.','RT_ST_Value'))

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi閱讀 7,841評(píng)論 0 10
  • pyspark.sql模塊 模塊上下文 Spark SQL和DataFrames的重要類: pyspark.sql...
    mpro閱讀 9,911評(píng)論 0 13
  • **2014真題Directions:Read the following text. Choose the be...
    又是夜半驚坐起閱讀 11,043評(píng)論 0 23
  • 每次在QQ空間被某個(gè)東西刷屏的時(shí)候,Lz就忍不住也想說(shuō)幾句。 今天,九月十八號(hào)。對(duì),大家都說(shuō)是“國(guó)恥日”。Lz并不...
    人間隱客閱讀 447評(píng)論 2 2
  • 2017年6月14日,日拱一卒,積硅步,精進(jìn)未來(lái)的自己。 今天剽悍晨讀分享的書(shū)是《窮查理寶典》,是查理-芒格的智慧...
    凡塵花仙子閱讀 1,063評(píng)論 3 4

友情鏈接更多精彩內(nèi)容