Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/257.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何确定点是否位于shapefile中的形状内?_C#_Gis - Fatal编程技术网

C# 如何确定点是否位于shapefile中的形状内?

C# 如何确定点是否位于shapefile中的形状内?,c#,gis,C#,Gis,我有一个定义城市形状的形状文件。我还有一组由纬度和经度定义的坐标 我需要能够确定这些点是否在shapefile中的任何形状内 目前我正在尝试使用easygis.net来解决这个问题,但它似乎不起作用 我相信shapefile中的坐标以UTM表示,但有一个偏移北距,我不知道如何更正它,将其转换为lat/long,或将我的lat/long对转换为匹配 我一直在研究其他库,如dotspatial和sharpmap,但我没有看到这个问题的直观答案 同时,我相信这是一个已经解决的问题。有没有可以轻松做到这

我有一个定义城市形状的形状文件。我还有一组由纬度和经度定义的坐标

我需要能够确定这些点是否在shapefile中的任何形状内

目前我正在尝试使用easygis.net来解决这个问题,但它似乎不起作用

我相信shapefile中的坐标以UTM表示,但有一个偏移北距,我不知道如何更正它,将其转换为lat/long,或将我的lat/long对转换为匹配

我一直在研究其他库,如dotspatial和sharpmap,但我没有看到这个问题的直观答案

同时,我相信这是一个已经解决的问题。有没有可以轻松做到这一点的库?或者如何将地图的偏移UTM转换为lat/long,或者如何将我的lat/long点转换为该偏移UTM

或者如何将地图的偏移UTM转换为lat/long,或者如何将我的lat/long点转换为该偏移UTM

这需要重新投影点(或形状文件的数据)。这可以通过(除非您的GIS已经支持)


一旦这样做了,它就是多边形中的一个点测试。有,尽管我经常使用。

如果您只需要将投影文件转换为地理坐标,那么在我看来,Qgis是最容易使用的工具,它是一个轻量级的基于草地的免费开放GIS软件。使用直接投影工具。
以下是一些示例代码,介绍如何使用DotSpatial首先处理重投影,然后使用Contains方法测试点是否位于多边形中

    public bool PointInShape() {
        // Load a shapefile.  If the shapefile is already using your custom projection, we don't need to change it.
        Shapefile wierdShapefile = Shapefile.OpenFile("C:\\MyShapefile.shp");

        // Note, if your shapefile with custom projection has a .prj file, then we don't need to mess with defining the projection.
        // If not, we can define the projection as follows:

        // First get a ProjectionInfo class for the normal UTM projection
        ProjectionInfo pInfo = DotSpatial.Projections.KnownCoordinateSystems.Projected.UtmNad1983.NAD1983UTMZone10N;

        // Next modify the pINfo with your custom False Northing
        pInfo.FalseNorthing = 400000;

        wierdShapefile.Projection = pInfo;

        // Reproject the strange shapefile so that it is in latitude/longitude coordinates
        wierdShapefile.Reproject(DotSpatial.Projections.KnownCoordinateSystems.Geographic.World.WGS1984);

        // Define the WGS84 Lat Lon point to test
        Coordinate test = new Coordinate(-120, 40);

        foreach (Feature f in wierdShapefile.Features) {
            Polygon pg = f.BasicGeometry as Polygon;
            if (pg != null)
            {
                if (pg.Contains(new Point(test)))
                {
                    // If the point is inside one of the polygon features
                    return true;
                }
            }
            else {
                // If you have a multi-part polygon then this should also handle holes I think
                MultiPolygon polygons = f.BasicGeometry as MultiPolygon;
                if (polygons.Contains(new Point(test))) {
                    return true;
                }
            }
        }

        return false;
    }

您的数据是针对北半球还是南半球?北半球。东距似乎正确,但北距将位置放置在1度纬度,这是不正确的。我很肯定这会起作用,但我在转换时遇到了问题。我从投影文件中读入WKT,然后创建一个从WGS84到读入投影的转换器。将我的横向/纵向坐标插入变压器,它应该可以工作。对吗?相反,我得到的是远远不够的coords。谢谢。我已经看过了,但我不确定它是否符合我的要求。我在网站上没有看到API,也没有看到可以与C#接口的东西。我确实通过DotSpatial和Proj.Net实现了这一点。这与我最终实现的非常接近。Cool=)。我希望其他偶然发现这一点的人有一个代码示例。如果速度给了你一个问题(例如加载特性的速度慢),我想你可以用形状本身做交叉测试。形状只加载向量,不需要shapefile读取所有属性。