什么是阅读,再present和渲染的地图数据的最佳方式是什么? [英] What is the best way to read, represent and render map data?

查看:295
本文介绍了什么是阅读,再present和渲染的地图数据的最佳方式是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有兴趣写一个简单的导航应用作为一个宠物项目。摸索了免费的地图数据后,我已经定居在href="http://www.census.gov/geo/www/tiger/tgrshp2007/tgrshp2007.html">美国人口普查局的TIGER 的2007

I am interested in writing a simplistic navigation application as a pet project. After searching around for free map-data I have settled on the US Census Bureau TIGER 2007 Line/Shapefile map data. The data is split up into zip files for individual counties and I've downloaded a single counties map-data for my area.

什么是阅读此地图数据转化为可用的格式,最好的方法是什么?

我应该如何:

  • 在阅读这些文件
  • 解析它们 - 经常EX pression或某些库,已经可以解析这些形状文件
  • 将数据加载到我的应用程序 - 如果我直接加载点到内存中的一些数据结构?使用小型数据库?我有没有必要为持续性,一旦你关闭了地图数据的应用程序。用户可以再次加载Shape文件。

什么是渲染图的最佳方式,一旦我在shapefile数据读取?

在理想情况下,我想能够读取一个县的地图数据shape文件和渲染所有的多行到屏幕上,并允许旋转和缩放。

Ideally I'd like to be able to read in a counties map data shapefile and render all the poly-lines onto the screen and allow rotating and scaling.

我应该如何:

  • 在转换纬度/经度点到屏幕坐标? - 据我所知shape文件使用经度和纬度的点。所以,很显然,我将不得不以某种方式将这些屏幕坐标来显示地图的功能。
  • 渲染的地图数据(A系列多段线道路,边界等)的方式,我可以很容易地旋转,缩放整个地图?
  • 渲染我整个地图作为一系列的砖,因此只有功能/查看区域内的线呈现?

例。 TIGER数据呈现为显示图:

Ex. of TIGER data rendered as a display map:

任何人只要有一定的经验和见识到了什么对我来说,在这些文件中,我应该怎么重新present他们(数据库,在内存中数据结构),在我的计划,我应该如何使读取(带有旋转的最佳途径/缩放)屏幕上的地图数据将AP preciated。

Anyone with some experience and insight into what the best way for me to read in these files, how I should represent them (database, in memory datastructure) in my program, and how I should render (with rotating/scaling) the map-data on screen would be appreciated.

编辑:为了澄清,我不希望使用任何谷歌或雅虎地图API。同样,我不想使用OpenStreetMap的。我正在寻找一个更从划痕的方法不是使用那些API /程序。这将是一个桌面应用程序。

To clarify, I do not want to use any Google or Yahoo maps API. Similarly, I don't want to use OpenStreetMap. I'm looking for a more from-scratch approach than utilizing those apis/programs. This will be a desktop application.

推荐答案

首先,我建议你使用的 2008年TIGER文件

First, I recommend that you use the 2008 TIGER files.

其次,正如其他人指出,有许多项目在那里,现在已经读入,除preT,转换,并使用数据。构建自己的解析器这个数据几乎是微不足道的,虽然,所以没有理由去通过其他项目的code和尝试提取你所需要的,除非你打算使用他们的项目作为一个整体。

Second, as others point out there are a lot of projects out there now that already read in, interpret, convert, and use the data. Building your own parser for this data is almost trivial, though, so there's no reason to go through another project's code and try to extract what you need unless you plan on using their project as a whole.

解析

建立自己的TIGER分析器(相当容易 - 线段只是一个数据库),并建立重要的是(线,多边形,信/名)之上​​的简单呈现,也将是相当容易的。你想看看在各种地图投影类型,在呈现阶段。最频繁使用的(和因此最熟悉的用户)是墨卡托投影的 - 它是相当简单,快捷。您可能需要与之配套的其他预测的发挥。

Building your own TIGER parser (reasonably easy - just a DB of line segments), and building a simple render on top of that (lines, polygons, letters/names) is also going to be fairly easy. You'll want to look at various map projection types for the render phase. The most frequently used (and therefore most familiar to users) is the Mercator projection - it's fairly simple and fast. You might want to play with supporting other projections.

这将看到如何投射出的地图,以及如何扭转这种投影(比如用户点击地图上的条款提供一点乐趣,你想看到的纬度/经度他们点击 - 需要扭转目前的投影式)。

This will provide a bit of 'fun' in terms of seeing how to project a map, and how to reverse that projection (say a user clicks on the map, you want to see the lat/lon they clicked - requires reversing the current projection equation).

渲染

当我开发我的渲染我决定把我的窗口上的一个固定大小(嵌入式设备),和一个固定倍率。这意味着我可以居中地图在纬度/经度,并与中心像素=中心纬度/经度在一个给定的放大倍率,并给予墨卡托投影,我可以计算出其像素重presented每个纬度/经度和反之亦然。

When I developed my renderer I decided to base my window on a fixed size (embedded device), and a fixed magnification. This meant that I could center the map at a lat/lon, and with the center pixel=center lat/lon at a given magnification, and given the mercator projection I could calculate which pixel represented each lat/lon, and vice-versa.

某些程序代替允许窗口而变化,并且代替使用倍率以及一固定点,它们使用两个固定点(通常是左上角和一个矩形的右下角限定窗口)。在这种情况下,它变得微不足道确定像素纬度/经度转移 - 这只是几个插值计算。旋转和缩放使该传递函数稍微更复杂,但不应该是相当如此 - 它仍然是一个长方形的窗口内插,但窗口角不需要以任何特定的方位相对于北。这增加了一些其他的情况(你可以把内而外的地图,查看它仿佛来自地球内部,例如),但这些都不是繁重的,并且可以处理,你的工作就可以了。

Some programs instead allow the window to vary, and instead of using magnification and a fixed point, they use two fixed points (often the upper left and lower right corners of a rectangle defining the window). In this case it becomes trivial to determine the pixel to lat/lon transfer - it's just a few interpolation calculations. Rotating and scaling make this transfer function a little more complex, but shouldn't be considerably so - it's still a rectangular window with interpolation, but the window corners don't need to be in any particular orientation with respect to north. This adds a few corner cases (you can turn the map inside out and view it as if from inside the earth, for instance) but these aren't onerous, and can be dealt with as you work on it.

一旦你得到了纬度/经度来完成,渲染线和多边形像素转移,除了正常的图形问题(如线条或多边形重叠不当,抗锯齿等边缘)相当简单。但呈现一个基本的丑图,如它由许多开源渲染器做的是相当简单的。

Once you've got the lat/lon to pixel transfer done, rendering lines and polygons is fairly simple except for normal graphics issues (such as edges of lines or polygons overlapping inappropriately, anti-aliasing, etc). But rendering a basic ugly map such as it done by many open source renderers is fairly straightforward.

您还将可以与距离和大圆计算,以发挥 - 例如拇指的一个很好的规则是,在赤道上每度纬度或经度约为111.1KM - 只有一个变化你接近或者极,而另一继续维持在111.1kM

You'll also be able to play with distance and great circle calculations - for instance a nice rule of thumb is that every degree of lat or lon at the equator is approximately 111.1KM - but one changes as you get closer to either pole, while the other continues to remain at 111.1kM.

存储和结构

您如何存储和引用数据,但是,在很大程度上取决于你打算用它做什么。如果你想使用相同的数据库结构,人口VS路由很多困难的问题出现 - 一个给定的数据的基础结构和索引将快速为一体,并减缓对其他

How you store and refer to the data, however, depends greatly on what you plan on doing with it. A lot of difficult problems arise if you want to use the same database structure for demographics vs routing - a given data base structure and indexing will be fast for one, and slow for the other.

使用Zip codeS和装载只有附近的拉链codeS适用于小型地图绘制项目,但如果你需要在全国范围内的路线,你需要一个不同的结构。有些实现有'叠加'的数据库只包含主要道路和捕捉航线覆盖(或通过多个覆盖 - 本地,城域,县,州,国家)。这导致快速的,但有时低效路由

Using zipcodes and loading only the nearby zipcodes works for small map rendering projects, but if you need a route across the country you need a different structure. Some implementations have 'overlay' databases which only contain major roads and snaps routes to the overlay (or through multiple overlays - local, metro, county, state, country). This results in fast, but sometimes inefficient routing.

平铺

平铺地图实际上是不容易的。在较低的放大倍率可以渲染整个地图,剪了起来。在更高的放大倍率,你不能呈现整个事情一次(由于内存/空间限制),所以你必须切片了。

Tiling your map is actually not easy. At lower magnifications you can render a whole map and cut it up. At higher magnifications you can't render the whole thing at once (due to memory/space constraints), so you have to slice it up.

切割线,在瓷砖的边界,所以你可以在不到完美的效果呈现个别瓷砖的结果 - 通常是什么做的是线呈现超越小块边界(或者,至少线路末端的数据被保存,虽然渲染停止一旦它发现它的脱落的边缘) - 这样可以减少发生线条看起来像他们这样做不是很匹配,因为他们在瓷砖旅游误差

Cutting lines at boundaries of tiles so you can render individual tiles results in less than perfect results - often what is done is lines are rendered beyond the tile boundary (or, at least the data of the line end is kept, though rendering stops once it finds it's fallen off the edge) - this reduces error that occurs with lines looking like they don't quite match as they travel across tiles.

您就会明白我在说什么,你的工作在这个问题上。

You'll see what I'm talking about as you work on this problem.

有是不平凡的,发现进入一个给定瓦片以及数据 - 一个线可以具有给定瓦片外两端,但跨越瓦片行进。您需要咨询显卡的本本这个(迈克尔Abrash的书是开创性的引用,免费提供现供职于preceding链接)。虽然会谈主要是关于游戏的窗口,裁剪,多边形的边,碰撞等所有的应用在这里。

It isn't trivial to find the data that goes into a given tile as well - a line may have both ends outside a given tile, but travel across the tile. You'll need to consult graphics books about this (Michael Abrash's book is the seminal reference, freely available now at the preceding link). While it talks mostly about gaming, the windowing, clipping, polygon edges, collision, etc all apply here.

一旦上述完成(通过调整现有的项目,或者做自己上面的),你可能要与其他场景和算法的发挥。

Once you have the above done (either by adapting an existing project, or doing the above yourself) you may want to play with other scenarios and algorithms.

反向地理编码是相当容易的。输入纬度/经度(或点击地图),并获得了最近地址。这教你如何跨preT地址沿TIGER数据线段。

Reverse geocoding is reasonably easy. Input lat/lon (or click on map) and get the nearest address. This teaches you how to interpret addresses along line segments in TIGER data.

基本地理编码是一个困难的问题。写一个地址解析器是一个有用和有趣的项目,然后用TIGER数据是不平凡的转换是为纬度/经度,但有很多乐趣。开始时简单和小,要求确切的名称和格式匹配,然后开始寻找到喜欢匹配和拼音匹配。有很多这方面的研究 - 看看搜索引擎项目的一些帮助这里

Basic geocoding is a hard problem. Writing an address parser is a useful and interesting project, and then converting that into lat/lon using the TIGER data is non-trivial, but a lot of fun. Start out simple and small by requiring exact name and format matching, and then start to look into 'like' matching and phonetic matching. There's a lot of research in this area - look at search engine projects for some help here.

查找两点之间的最短路径是一个不平凡的问题。还有很多,很多算法做的,其中大部分是专利。我建议,如果您试试这个去与一个简单的算法,自己设计的,然后做一些研究和设计比较艺术的状态。这是一个很大的乐趣,如果你到图论。

Finding the shortest path between two points is a non-trivial problem. There are many, many algorithms for doing that, most of which are patented. I recommend that if you try this go with an easy algorithm of your own design, and then do some research and compare your design to the state of the art. It's a lot of fun if you're into graph theory.

继路径和pre-先发制人给予说明并不像它看起来乍一看容易。给定的一组指令的以纬度/经度对相关联的阵列,'后续'使用外部输入(全球定位系统,或模拟GPS)的途径和开发了一种算法,为用户提供了说明,它们相互接近真实相交。请注意,有更多的纬度/经度对不是因弯曲道路等的说明,你就会需要检测行进方向等。很多角落情况下,你不会看到,直到你尝试实现它。

Following a path and pre-emptively giving instructions is not as easy as it looks on first blush. Given a set of instructions with an associated array of lat/lon pairs, 'follow' the route using external input (GPS, or simulated GPS) and develop an algorithm that gives the user instructions as they approach each real intersection. Notice that there are more lat/lon pairs than instructions due to curving roads, etc, and you'll need to detect direction of travel and so forth. Lots of corner cases you won't see until you try to implement it.

的兴趣搜索点这个是有趣的 - 你需要找到当前位置,以及所有感兴趣的点(TIGER不是一部分,使你自己或让其他来源)内发端 - 一定距离(行驶距离的直线距离,或更难)。这一个是有趣的,你必须POI数据库转换成格式,很容易在这种情况下进行搜索。你不能花时间去通过数以百万计的条目,做距离计算(的sqrt(x ^ 2 + Y ^ 2)),并返回结果。你需要有某些方法或算法来削减数据量先坐下。

Point of interest search. This one is interesting - you need to find the current location, and all the points of interest (not part of TIGER, make your own or get another source) within a certain distance (as the crow flies, or harder - driving distance) of the origin. This one is interesting in that you have to convert the POI database into a format that is easy to search in this circumstance. You can't take the time to go through millions of entries, do the distance calculation (sqrt(x^2 + y^2)), and return the results. You need to have some method or algorithm to cut the amount of data down first.

旅行商。路由与多个目标。只是一个更难的版本,普通路由。

Traveling salesman. Routing with multiple destinations. Just a harder version of regular routing.

您可以找到一些链接,许多项目和信息来源关于这个主题 href="http://delicious.com/stienman/gis">。

You can find a number of links to many projects and sources of information on this subject here.

祝你好运,并请发表不管你做什么,不管多么基本的或丑陋,以便其他人可以受益!

Good luck, and please publish whatever you do, no matter how rudimentary or ugly, so others can benefit!

这篇关于什么是阅读,再present和渲染的地图数据的最佳方式是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆