在 C# 中生成地理参考图像

发布于 2024-07-14 18:45:21 字数 375 浏览 11 评论 0原文

我想创建一些热图样式图块以使用开放图层覆盖在我们的底图上。 基本上,我想将一些边界框划分为网格,并根据样本中有多少点落在该网格正方形内,使用不同的颜色显示网格的每个正方形。

涉及的技术有C#、OpenLayers、SQL Server 2008和GeoServer。

我的问题基本上是一种通用方法,我不太确定将凿子的尖端放在哪里。

我的最终目标是能够采用任意边界框,计算适合该边界框的 x 英里 x 英里网格,迭代一组单独的点并将它们分配给一个网格方块或另一个网格方块,这样我可以计算每个网格正方形的点密度,然后根据密度为网格着色,然后使用开放图层将其覆盖在 CloudMade 底图上。

任何帮助,无论是整个事情还是其中的任何部分,我们都将不胜感激。

I want to create some heat-map style tiles to overlay over our base maps using Open Layers. Basically, I want to divide some some bounding box into a grid, and display each square of the grid using a different color based on how many points of a sample fall within that grid square.

The technologies involved are C#, OpenLayers, SQL Server 2008 and GeoServer.

My question is basically one of general approach, I'm not really sure where to put the tip of the chisel on this one.

My ultimate goal is to be able to take any arbitrary bounding box, calculate an x-mile by x-mile grid that fits within that bounding box, the iterate over a collection of individual points and assign them to one grid square or another so I can calculate point density per grid square, then color the grid according to the densities, then overlay that on a CloudMade base map using Open Layers.

Any help at all would be greatly appreciated, on the whole thing or any piece of it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

不喜欢何必死缠烂打 2024-07-21 18:45:21

如果您的边界框是轴对齐的,那么这相当简单。 只需制作您的图像,然后手动为其创建一个世界文件即可。 世界文件只有 6 行文本,您已经知道所需的一切(x 和 y 像素大小、左上角的坐标)。

只需确保您使用左上角像素的中心,而不是框的角。

------ 以下是制作世界文件的方法 ----------

假设您的边界框的左上角位于 203732x598374,并且您想要一个具有东边宽 200m 的矩形的图像<->西、南北高300m。

您将创建一个具有适当像素数的图像,然后创建一个包含以下 6 行的世界文件:

200
0
0
-300
203632
598524

这对应于:

200 == size of one pixel in X
0 == shear1
0 == shear2
-300 == size of one pixel in Y (from top down)
203632 == left edge - 1/2 pixel size (to center on pixel instead of edge of box)
598524 == top edge - 1/2 pixel size (to center on pixel instead of edge of box)

如果您使用 .png 图像,您将需要使用相同的名称保存它,但是作为.pgw。 如果您使用 .jpg,则为 .jgw 等。

有关完整详细信息,请参阅:
世界文件维基

If your bounding box is axis aligned, this is fairly simple. Just make your image, and create a world file for it by hand. The world file is just 6 lines of text, and you already know everything needed (x & y pixel size, coordinate of your upper left corner).

Just make sure that you use the CENTER of the upper left corner pixel, not the corner of the box.

------ Here's how you'd make the world file -------

Say your bounding box's upper left corner is at 203732x598374, and you want an image that has rectangles that are 200m wide east<->west and 300m tall north<->south.

You'd make an image that was the appropriate number of pixels, then a world file that had the following 6 lines:

200
0
0
-300
203632
598524

This corresponds to:

200 == size of one pixel in X
0 == shear1
0 == shear2
-300 == size of one pixel in Y (from top down)
203632 == left edge - 1/2 pixel size (to center on pixel instead of edge of box)
598524 == top edge - 1/2 pixel size (to center on pixel instead of edge of box)

If you use a .png image, you'll want to save this with the same name, but as .pgw. If you use a .jpg, it'd be .jgw, etc.

For complete details, see:
Wiki on World Files

念﹏祤嫣 2024-07-21 18:45:21

“将一些边界框划分为网格,并根据样本中有多少点落在该网格方块内,使用不同的颜色显示网格的每个方块。” 这是一个栅格,有GeoServer 中的功能,用于通过颜色阴影、图例等显示这些内容。 我认为使用这些功能比在 C# 中创建图像图块更加灵活。

来自地理服务器文档:

栅格数据不仅仅是一张图片,
相反,它可以被认为是一个网格
地理参考信息,很多
就像图形是视觉网格一样
信息(红色的组合,
绿色和蓝色)。 与图形不同的是,
仅包含视觉数据,每个
栅格网格中的点/像素可以有
许多不同的属性,
可能他们都没有
固有的视觉组件。

在其他 GIS 软件包中,这也称为专题制图、等高线图、热图或 2.5D 图。

您可以使用免费的 GIS,例如 Grass创建栅格网格,但根据您的描述,您不需要插值(因为每个单元格至少包含一个点)因此,编写自己的代码可能同样容易。

编辑:有一个开源库 GDAL 您可以使用它在 各种格式。 有 C# 绑定。

"Dividing some some bounding box into a grid, and displaying each square of the grid using a different color based on how many points of a sample fall within that grid square." This is a raster and there are features in GeoServer for displaying these with colour shading, legends and so on. I think it will be more flexible to use these features than to create image tiles in C#.

From the GeoServer documentation:

Raster data is not merely a picture,
rather it can be thought of as a grid
of georeferenced information, much
like a graphic is a grid of visual
information (with combination of reds,
greens, and blues). Unlike graphics,
which only contain visual data, each
point/pixel in a raster grid can have
lots of different attributes, with
possibly none of them having an
inherently visual component.

This is also called thematic mapping or contour plots or heatmaps or 2.5D plots in other GIS packages.

You could use a free GIS like Grass to create the raster grids, but from your description you don't need to interpolate (because every cell contains at least one point) so it might be just as easy to roll your own code.

EDIT: there is an open source library GDAL which you can use to write raster files in various formats. There are C# bindings.

九八野马 2024-07-21 18:45:21

我认为计算左上角像素中心的公式是错误的。 在该示例中,左上角像素的中心将位于 (203732,598374) 的右下方。 那么不应该是下面这样吗?

203832 == left edge + 1/2 pixel size (to center on pixel instead of edge of box)
598224 == top edge - 1/2 pixel size (to center on pixel instead of edge of box)

I think the formulas for computing the center of the upper left pixel are wrong. In the example, the center of the upper left pixel would be down and to the right of (203732,598374). So shouldn't it be the following?

203832 == left edge + 1/2 pixel size (to center on pixel instead of edge of box)
598224 == top edge - 1/2 pixel size (to center on pixel instead of edge of box)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文