谷歌地球中的动态地图管理
我的目标是通过使用动态输入 Postgis 数据库的数据在谷歌地图上显示各种形状(多边形、点、线串)(我的意思是我们可以实时看到地图中的修改)。 我正在寻找一种方法来做到这一点,使用 postgis 中已经提供的空间结构(已经指定形状是线串还是多边形等),而不是解析出坐标,然后在谷歌地图中重新输入空间结构。我看到 google 地图 api 现在与 kml 数据格式兼容。然后我读到我必须将 postgis 数据转换为 kml 格式。 我在论坛上阅读了一些有关通过 FWTools 将 postgis 数据转换为 kml 的实际过程的信息,但没有看到任何对我有帮助的内容。我是 kml 新手,但熟悉 postgis、perl 和 PHP。有没有关于将postgis数据转换为kml的过程的教程?我可以从哪里开始?感谢您的帮助
My goal is to display various shapes(polygons, points, linestring) on google maps by using data entered into a Postgis database dynamically(i mean by that we can see modifications in the map in real time).
I was looking for a way to do this that used the spatial structure already provided in postgis(already designating if shape is a linestring or polygon, etc) instead of parsing out the coordinates and then re-entering spatial structure in google maps. I saw that google maps api is now compatible with kml data formats. And then I read that i have to convert postgis data to kml format.
I've done some reading in the forums about the actual process of converting postgis data to kml via FWTools, but didn't see anything that would help me. I'm new to kml but am familiar with postgis and perl and PHP. Is there a tutorial for the process of converting postgis data to kml? Where can I get started? Thanks for any help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用PostGIS直接转换为KML:
ST_AsKML 是几种输出格式之一,包括 WKT、GML、GeoJSON 等。
要在 Google Earth 中显示动态数据,常见的模式是使用带有 NetworkLink 元素。让链接的
viewRefreshMode
等于onStop
,Google 地球将发出附加了边界框参数的请求(可能是向 PHP 提供的 URL)。使用边界框查询 PostGIS 数据库中的要素,并以 kml 形式返回结果。如果您有很多很多功能,但只想检索用户正在查看的区域中的功能,那么这非常有用。根据应用程序的复杂性,您可能还需要查看 GeoDjango。 (熟悉 PostGIS 是一个很好的开始!)
You can use PostGIS to convert to KML directly:
ST_AsKML is one of several output formats, including WKT, GML, GeoJSON, etc.
To show dynamic data in Google Earth, a common pattern is to use KML with a NetworkLink element. Have the link's
viewRefreshMode
equal toonStop
and Google Earth will make requests (to a URL served by PHP, presumably) with bounding box parameters attached. Use the bounding box to query features in the PostGIS database, and return results as kml. This is great if you have lots and lots of features, but only want to retrieve those in the region the user is looking at.Depending on the complexity of your application, you may also want to look at GeoDjango. (Familiarity with PostGIS is a big head start!)
您可以使用文本转换函数从 Postgres DB 获取空间数据的文本表示,就像
解析字符串一样,使用各种 API 函数创建对象(取决于 PostGIS 几何类型)并将这些对象附加到主 GE以类似于 DOM 的方式的插件对象。
如果您熟悉 JavaScript 并且有 XML 的基础知识,http 是一个好的开始://code.google.com/apis/earth/documentation/reference/
不要忘记为您的对象指定唯一 ID,以便您稍后可以找到它们并进行删除/修改。
也许您可以在此处获得一些灵感,显示链接的“locator.js”文件并查看函数 PaintSubField (协调)...这是另一种方法,有点粗糙但有效,避免弄乱太多单独的父/子对象和结构
您也可能需要咨询示例应用程序 并使用 用于“快速原型设计”和“实时”的代码游乐场,
您至少需要一个可以将生成/重绘例程链接到的事件。
祝你好运
迈克·D
You can get a textual representation of the spatial data from a Postgres DB using a text conversion function, like
then you parse the string, create your objects using various API functions - depending on the PostGIS geometry type - and append these object to the main GE plugin object in a DOM like way.
If you are familiar with JavaScript and have a fundamental knowledge of XML, a good start is http://code.google.com/apis/earth/documentation/reference/
Don't forget to specify unique ID's to your objects so you can find them later to drop/modify.
Maybe you can get some inspirations here, display the linked "locator.js" file and look at function PaintSubField(Coord) ... this is another way, bit crude but effective, avoiding to mess around with too many individual parent/child objects and structures
You also may want to consult sample applications and use the code playground for "rapid prototyping"
re "realtime" you need at least an event that you can link your generation/redraw routines to.
Good luck
MikeD