我想完全转移elasticsearch以使用PostGIS扩展来过滤PostGreSQL当前处理的元素.
为此,我必须选择围绕(多)多边形的给定距离内的每个结果.
那些多边形可能很复杂(数百个点).
我在一年前看到,elasticsearch无法处理这样的过滤器.
在一年中,ES已经有了很大的发展(包括一个主要版本),那么现在支持的那种过滤是什么?如果没有,有什么计划吗?
为了解释,这是一个简单的用例:
将此多边形视为粗略描述巴黎"Ile delacité"边界:
{
"type": "MultiPolygon",
"coordinates": [
[
[
[
2.339546203568933,
48.857710541463412
],
[
2.345168113663295,
48.856750530470009
],
[
2.350618362380806,
48.855056348509926
],
[
2.352077484084764,
48.853785674412812
],
[
2.352592468215498,
48.851611335037532
],
[
2.348730087234629,
48.852543206332619
],
[
2.343194007828603,
48.855084585345963
],
[
2.339546203568933,
48.857710541463412
]
]
]
]
}
Run Code Online (Sandbox Code Playgroud)
考虑另一个岛对面的位置(因此,在多边形之外):
{
"type": "Point",
"coordinates": [
2.359378457022193,
48.850358223189644
]
}
Run Code Online (Sandbox Code Playgroud)
以下是使用Django ORM的一些示例查询(我可以提供SQL等价但我认为这不相关):
>>> Location.objects.filter(point__within=(area.polygon))
[]
>>> Location.objects.filter(point__distance_lte=(area.polygon, D(m=500)))
[]
>>> Location.objects.filter(point__distance_lte=(area.polygon, D(m=550)))
[<Location: Ile saint louis>]
Run Code Online (Sandbox Code Playgroud)
该 …
我有一个包含各种定义多边形的数据库,这些多边形表示商业园区地图上建筑物的外边界。
如果我在 Management Studio 中执行 Select,我会得到类似于以下的结果:
LocationCode LocationPolygon
1 POLYGON((1 1, 2 1, 2 2, 1 2, 1 1))
2 POLYGON((10 10, 20 10, 20 20, 10 20, 10 10))
Run Code Online (Sandbox Code Playgroud)
我想得到的是以下内容:
LocationCode PointX PointY
1 1 1
1 2 1
1 2 2
1 1 2
2 10 10
etc etc etc
Run Code Online (Sandbox Code Playgroud)
在 SQL 查询中使用 SQL Server 从多边形中提取点时,我看不到任何地方?我显然可以取整个多边形,然后在客户端上完成其余的工作,但如果可能的话,我宁愿处理 SQL。
任何帮助指出我正确的方向。
我想学习如何使用postGIS构建应用程序.我想知道是否有好的开源示例我可以看看?我特别感兴趣的是那些不仅使用postgres存储地图数据,而且在应用程序代码中广泛使用postGIS特殊功能(聚合和SQL-MM,即ST_*函数).谢谢!
大家好我有一个问题:如何在postgis数据库中插入一个带有Ne_latitude,NE_longitude,SW_latitude,SW_longitude的框(矩形),并在顶部构建一个INDEX来检索不同框之间的交集?
提前致谢
根据他们的文档,空间对象可以是以下内容
POINT(0 0)
LINESTRING(0 0,1 1,1 2)
POLYGON((0 0,4 0,4 4,0 4,0 0),(1 1, 2 1, 2 2, 1 2,1 1))
MULTIPOINT(0 0,1 2)
MULTILINESTRING((0 0,1 1,1 2),(2 3,3 2,5 4))
MULTIPOLYGON(((0 0,4 0,4 4,0 4,0 0),(1 1,2 1,2 2,1 2,1 1)), ((-1 -1,-1 -2,-2 -2,-2 -1,-1 -1)))
GEOMETRYCOLLECTION(POINT(2 3),LINESTRING(2 3,3 4))
Run Code Online (Sandbox Code Playgroud)
但是,没有圆形类型,我可以只存储一个点及其半径.并且具有相同的功能,当我查询该点是否存在于该圈时,我可以获得该圈的边界框.
postgis geospatial spatial-query spatial-index postgresql-9.3
我在使用 H2 和 GeoDB(内存中,junit)时遇到问题。
此外,使用 Hibernate 5(每个包的最新版本,包括 hibernate-spatial)和 Spring 4。
通过 id 实体持久化和查询工作得很好。可以毫无问题地识别几何类型。
当我尝试使用地理空间函数查询数据库时出现问题,并且 Hibernate 失败说他找不到该函数:
[ERROR] 2015-12-16 11:16:15,000: org.hibernate.engine.jdbc.spi.SqlExceptionHelper.logExceptions:129: Function "ST_CONTAINS" not found; SQL statement:
select geoentity0_.id as id1_0_, geoentity0_.location as location2_0_, geoentity0_.name as name3_0_ from GEO_ENTITY geoentity0_ where ST_Contains(geoentity0_.location, ?)=1 [90022-190]
Run Code Online (Sandbox Code Playgroud)
看起来像方言的问题。这是我正在使用的(在persistence.xml中):
<property name="hibernate.dialect" value="org.hibernate.spatial.dialect.h2geodb.GeoDBDialect" />
Run Code Online (Sandbox Code Playgroud)
这些是我正在使用的 deps:
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.190</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.opengeo</groupId>
<artifactId>geodb</artifactId>
<version>0.7</version>
<scope>test</scope>
</dependency>
Run Code Online (Sandbox Code Playgroud)
我做错了什么,我该如何解决?
编辑:添加 h2gis
我试过添加h2gis到我的 deps 但没有改变错误。我也试着来代替geodb用h2gis,具有相同的结果。
<dependency>
<groupId>org.orbisgis</groupId>
<artifactId>h2spatial-ext</artifactId>
<version>1.2.3</version>
</dependency>
Run Code Online (Sandbox Code Playgroud) 我正在使用stSPARQL,参考文献说:
xsd:float strdf:area(strdf:geometry A):如果曲面是多边形或多多边形,则返回曲面的面积。
所以我正在尝试:
PREFIX geo: <http://geo.linkedopendata.gr/gag/ontology/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX strdf: <http://strdf.di.uoa.gr/ontology#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
...
?municipality geo:has_geometry ?geometry . // so far so good (checked)
FILTER(strdf:area(?geometry) = ?area) .
Run Code Online (Sandbox Code Playgroud)
结果我什么也没得到。我的总体目标是获得所有城市的总面积,但我连一个都无法获得!任何想法?
请注意,这是我第一次使用空间度量函数,因此我想做的是收集并显示 的结果strdf:area(),但我失败了!
?geometry 的第一个结果是:
“多重多边形((476162.8125 3949684,476195.687499999 3949675,476216.000000001 3949675,476226.1875 3...更多
编辑:
如果我尝试这样做:?area = strdf:area(?geometry) .,我会收到错误:
在第 15 行第 9 列遇到“”=“=“”。期待以下之一:“(”...“!”...“^”...“a”... ... .. 。
我正在尝试从空间查询(SQL Server 2016)创建参数化存储过程。当参数(@long/经度)被硬编码时(例如 174.7115),底层空间查询工作正常。
当我尝试使用经度 ( ) 参数创建存储过程时,@long出现以下错误。
消息 6522,级别 16,状态 1,过程 Spatial8,第 5 行 [批处理起始行 0] 在执行用户定义的例程或聚合“地理”期间发生 .NET Framework 错误: System.FormatException:24141:需要一个数字输入的位置11。输入有@Long。System.FormatException:在 Microsoft.SqlServer.Types.WellKnownTextReader.RecognizeDouble() 在 Microsoft.SqlServer.Types.WellKnownTextReader.ParsePointText(Boolean parseParentheses) 在 Microsoft.SqlServer.Types.WellKnownTextReader.ParseTaggedText(OpenGisType 类型) 在 Microsoft.SqlServer.Types .WellKnownTextReader.Read(OpenGisType 类型,Int32 srid)在 Microsoft.SqlServer.Types.SqlGeography.ParseText(OpenGisType 类型,SqlChars taggedText,Int32 srid)在 Microsoft.SqlServer.Types.SqlGeography.GeographyFromText(OpenGisType 类型,SqlChars taggedText,Int32 srid) ) ................................
这是存储过程..
CREATE PROC Spatial8 @Long decimal(9,6)
AS
DECLARE @Car geography;
SET @Car = geography::STGeomFromText ('Point(@Long -36.81143)', 4326);
/* Add 20m buffer to each side of the cars position (Lat and long) */ …Run Code Online (Sandbox Code Playgroud) t-sql sql-server stored-procedures spatial-query sql-server-2016
我在 AWS Postgres 服务器中有两个表(我正在使用 DBeaver 进行查询)。
表 1 是我从名为 的 S3 存储桶导入的 shapefile uk_counties,其中列出了英国所有县的几何图形(SRID = 27700 - shapefile 可以在此处找到)。
表 2 被称为demand_origin并 包含字段origin_city(英国的地点)和两个字段latitude和longitude(其中包含 中地点的纬度和经度origin_city)。
通过加入uk_counties(shapefile) 和demand_origin,我想通过查找各自的经度与县的 shapefile 相交的位置,将一个县分配给英国的各个地方。
问题是这个连接一直显示为空。经过大量调查后,shapefile 中的几何图形似乎被映射到几内亚湾(纬度 = 0,经度 = 0 及其周围)。
请参阅莱斯特的 shapefile 作为示例:
我的猜测是,几何图形使用的是北距/西距,而不是纬度/经度,因此 PostGIS 将这些形状映射到 lat=0、long=0 左右,因此可能需要重新校准。
以下是莱斯特和其他县的几何形状的片段:
| ctua23nm | 几何学 |
|---|---|
| 约克 | 多边形 ((464216.99650000036 462110.9015999995, 464266.20299999975 462093.0965999998, 464270.3008000003 462094.3962999992, 46428 9.8992999997 4 |
| 德比 | 多边形 ((434972.3005999997 341311.7999000009, 434986.3008000003 341310.40029999986, … |
postgresql postgis spatial-query amazon-web-services amazon-rds
我有+ 10k点(纬度,经度),我正在构建一个应用程序,向您显示距离用户位置最近的k点.
我认为这是一个非常普遍的问题,我不想重新发明轮子.我正在学习四叉树.这似乎是解决这个空间问题的好方法.
我正在使用这些工具:
构建Quadtree并不难:http://donar.umiacs.umd.edu/quadtree/points/pointquad.html但是一旦我创建了树并将其保存到db(MySQL或MongoDb),我如何运行查询?
我需要运行这样的查询:
这样做的标准和常用方法是什么?
编辑1:
我已经将+ 10k点加载到MongoDB(地理空间索引)中,乍一看它运行正常.无论如何我发现PostGis:
PostGIS是PostgreSQL对象 - 关系数据库系统的扩展,它允许GIS(地理信息系统)对象存储在数据库中.
所以我想我会试试PostGis.
我也找到了SimpleGeo.您可以在云中存储点/位置,然后通过API查询它们:https://simplegeo.com/docs/tutorials/python#how-do-radial-nearby-query
spatial-query ×10
geospatial ×5
postgis ×4
spatial ×2
sql-server ×2
amazon-rds ×1
geo ×1
gis ×1
h2 ×1
hibernate ×1
mapserver ×1
postgresql ×1
python ×1
rdf ×1
sparql ×1
sql ×1
t-sql ×1