在着色ASP.NET shape文件地图 [英] Coloring a Shapefile map in ASP.NET

查看:177
本文介绍了在着色ASP.NET shape文件地图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有马里兰shape文件地图由拉链code分开。我想要做的是色彩的基础上,我在数据库中查找一个值的每个区域。目前,我使用ASP.NET与SharpMap中包。基本的问题是:

I have a Shapefile map of Maryland separated by zipcode. What I'd like to do is color each area based on a value I'm looking up in a database. Currently, I'm using ASP.NET with the SharpMap package. The basic questions are:

1)的如何的形状,其拉链code关联?的我可以在SharpMap的ExecuteIntersectionQuery与BoundingBox的设置为地图的程度生成ZIP codeS名单,但我不知道怎么那么结果表中的每一行与它重新presents形连接。

1) How do I associate a shape with its zipcode? I can generate the list of zipcodes using SharpMap's ExecuteIntersectionQuery with the BoundingBox set as the extent of the map, but I have no idea how to then connect each row of the resulting table with the shape it represents.

2)一旦我有机会获得一个单独的形状,知道我要什么颜色,的我怎么分配的颜色与形状?的在SharpMap中,我可以颜色VectorLayer,但VectorLayer是从源.shp文件生成的,而不是一个形状。

2) Once I have access to an individual shape and know what color I want, how do I assign the color to the shape? In SharpMap, I can color a VectorLayer, but a VectorLayer is generated from a source .shp file, not a shape.

我打开使用其他的免费地图包除了SharpMap中(所以没有ArcGIS中),但出于法律原因我不能使用的GoogleMaps。

I'm open to using other free map packages besides SharpMap (so no ArcGIS), but for legal reasons I can't use GoogleMaps.

我觉得这应该是比较简单的,但是试图找到SharpMap中任何像样的资源是pretty困难。

I feel like this should be relatively simple, but trying to find any decent resource for SharpMap is pretty difficult.

编辑:好吧,我只是通过阅读哪些文件有做了很多的过程。通过设置shape文件的FilterDelegate,我可以做一个图层只包括其中的zip code相匹配的一定值行。现在我唯一的问题是使委托过滤器寻找一个不同的压缩$ C $每次℃。我可以通过除了FeatureDataRow另一个参数?我应该再打一个全局变量?

Alright, I've made a lot of process just by reading over what documentation there is. By setting the FilterDelegate of ShapeFile, I can make a layer consist of only the rows where the zip code matches a certain value. Now my only problem is making the delegate filter look for a different zip code each time. Can I pass another parameter besides the FeatureDataRow? Should I resort to a global variable?

推荐答案

您需要使用thematics做到这一点。

You'll need to use thematics to do this.

我假设你已经有了一些code,它配置您的地图,它的图层。你shape文件是VectorLayer。

I'll assume you already have some code that configures your map and it's layers. Your shapefile is a VectorLayer.

VectorLayer shapefileLayer = GetMyShapefileLayer();
shapefileLayer.Theme = new SharpMap.Rendering.Thematics.CustomTheme(GetStyleForShape);

然后,方法GetStyleForShape被称为每个地图需要一个风格渲染时间。它看起来像这样: -

Then, method GetStyleForShape is called every time the map needs a style for rendering. It looks like this:-

private SharpMap.Styles.VectorStyle GetStyleForShape(SharpMap.Data.FeatureDataRow row, SharpMap.Layers.Layer layer)
    {
}

在该方法中,创建并返回一个VectorStyle。与功能它试图使相关的表数据作为参数传递给该方法传递。

In the method, you create and return a VectorStyle. The table data associated with the feature it's trying to render is passed as a parameter to this method.

所以,你可以使用行参数来获取你的拉链code,你需要做的计算它的风格,配置的风格,并返回它的任何逻辑。

So you can use the row parameter to get your zip code, do whatever logic you need to do to calculate it's style, configure that style and return it.

这个方法(可能)被调用了很多,所以考虑将款式和重用他们,而不是每次重新创建它们。

This method (potentially) gets called a lot, so consider storing the styles and reusing them, rather than recreating them every time.

希望这有助于。

这篇关于在着色ASP.NET shape文件地图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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