{"id":15699222,"url":"https://github.com/zxyao145/corespatial","last_synced_at":"2025-05-09T02:27:10.571Z","repository":{"id":152251024,"uuid":"250008344","full_name":"zxyao145/CoreSpatial","owner":"zxyao145","description":"Based on .Net Standard v2.1, for reading and writing esri shapefile files. 基于.Net Standard v2.1, 用于shapefile文件读写。","archived":false,"fork":false,"pushed_at":"2021-04-02T06:57:48.000Z","size":1351,"stargazers_count":6,"open_issues_count":2,"forks_count":4,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-31T21:28:09.602Z","etag":null,"topics":["csharp","dotnet-core","dotnet-library","dotnet-standard","gis","shapefile"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zxyao145.png","metadata":{"files":{"readme":"README-en.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2020-03-25T14:56:17.000Z","updated_at":"2023-03-17T13:16:05.000Z","dependencies_parsed_at":null,"dependency_job_id":"a06a6680-e1c0-4daf-81eb-79054aed5fd8","html_url":"https://github.com/zxyao145/CoreSpatial","commit_stats":{"total_commits":49,"total_committers":2,"mean_commits":24.5,"dds":0.08163265306122447,"last_synced_commit":"2ade28eed84527cdfe3c5adc222a369a08c5cf16"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zxyao145%2FCoreSpatial","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zxyao145%2FCoreSpatial/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zxyao145%2FCoreSpatial/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zxyao145%2FCoreSpatial/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zxyao145","download_url":"https://codeload.github.com/zxyao145/CoreSpatial/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253177144,"owners_count":21866273,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["csharp","dotnet-core","dotnet-library","dotnet-standard","gis","shapefile"],"created_at":"2024-10-03T19:38:55.000Z","updated_at":"2025-05-09T02:27:10.549Z","avatar_url":"https://github.com/zxyao145.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CoreSpatial\n\n[中文](./README.md)\n\n\n### Purpose\nCoreSpatial is a class library based on .Net Standard v2.1 to read and write shapefiles. It supports the reading and writing of projection file .prj (support by ProjNet).\n\n\n### nuget\n|  Library   | nuget  |\n|  ----  | ----  |\n| CoreSpatial | [![NuGet Status](https://img.shields.io/nuget/v/CoreSpatial)](https://www.nuget.org/packages/CoreSpatial) |\n| CoreSpatial.Converter | [![NuGet Status](https://img.shields.io/nuget/v/CoreSpatial.Converter?style=plastic)](https://www.nuget.org/packages/CoreSpatial.Converter) |\n\n\n### Project information\n+ .NET Standard v2.1\n+ Supports the reading and writing of shapefile\n+ Using **ProjNet** to support reading and writing .prj files\n\n\n### Usage\nread:\n```c#\nIFeatureSet fs = FeatureSet.Open(shpPath);\n...\n```\n\nwrite:\n```c#\nfs.Save(shpPath);\n```\n\ncreate new shapefile:\n```c#\nvoid CreatePoint()\n{\n\tIFeatureSet fs = new FeatureSet(FeatureType.Point);\n\tvar point1 = new GeoPoint(133, 30);\n\tvar point2 = new GeoPoint(133, 32);\n\tvar point3 = new GeoPoint(134, 30);\n\n\tvar feature1 = new Feature(new Geometry(point1));\n\tvar feature2 = new Feature(new Geometry(point2));\n\tvar feature3 = new Feature(new Geometry(point3));\n\n\tfs.Features.Add(feature1);\n\tfs.Features.Add(feature2);\n\tfs.Features.Add(feature3);\n\tfs.Crs = Crs.Wgs84Gcs;\n\n\tvar dataTable = new DataTable();\n\tdataTable.Columns.Add(\"名称\", typeof(string));\n\tdataTable.Columns.Add(\"id\", typeof(int));\n\tvar row1 = dataTable.NewRow();\n\tvar row2 = dataTable.NewRow();\n\tvar row3 = dataTable.NewRow();\n\n\trow1[0] = \"点1\";\n\trow1[1] = 1;\n\n\trow2[0] = \"点2\";\n\trow2[1] = 2;\n\t\n\trow3[0] = \"点3\";\n\trow3[1] = 3;\n\n\tdataTable.Rows.Add(row1);\n\tdataTable.Rows.Add(row2);\n\tdataTable.Rows.Add(row3);\n\n\tfs.AttrTable = dataTable;\n\n\tfs.Save(\"../createNew/point.shp\");\n}\n\nvoid CreateMultiPoint()\n{\n\tIFeatureSet fs = new FeatureSet(FeatureType.MultiPoint);\n\n\tvar point1 = new GeoPoint(133, 30);\n\tvar point2 = new GeoPoint(133, 32);\n\tvar point3 = new GeoPoint(134, 30);\n\n\tvar point4 = new GeoPoint(134, 34);\n\tvar point5 = new GeoPoint(135, 35);\n\n\tvar multiPoint1 = new MultiPoint(new List\u003cGeoPoint\u003e()\n\t{\n\t\tpoint1,point2,point3\n\t});\n\n\tvar multiPoint2 = new MultiPoint();\n\tmultiPoint2.Points.Add(point4);\n\tmultiPoint2.Points.Add(point5);\n\t\n\n\tvar feature1 = new Feature(new Geometry(multiPoint1));\n\tvar feature2 = new Feature(new Geometry(multiPoint2));\n\n\tfs.Features.Add(feature1);\n\tfs.Features.Add(feature2);\n\tfs.Crs = Crs.Wgs84Gcs;\n\n\tvar dataTable = new DataTable();\n\tdataTable.Columns.Add(\"名称\", typeof(string));\n\tdataTable.Columns.Add(\"id\", typeof(int));\n\tvar row1 = dataTable.NewRow();\n\tvar row2 = dataTable.NewRow();\n\n\trow1[0] = \"多点1\";\n\trow1[1] = 1;\n\n\trow2[0] = \"多点2\";\n\trow2[1] = 2;\n\n\tdataTable.Rows.Add(row1);\n\tdataTable.Rows.Add(row2);\n\n\tfs.AttrTable = dataTable;\n\n\tfs.Save(\"../createNew/multipoint.shp\");\n}\n\nvoid CreatePolyLine()\n{\n\t\n\tIFeatureSet fs = new FeatureSet(FeatureType.PolyLine);\n\n\tvar point1 = new GeoPoint(133, 30);\n\tvar point2 = new GeoPoint(133, 32);\n\tvar point3 = new GeoPoint(134, 30);\n\n\tvar point4 = new GeoPoint(134, 34);\n\tvar point5 = new GeoPoint(135, 35);\n\n\t//line ring\n\tvar polyLine1 = new PolyLine(new List\u003cGeoPoint\u003e()\n\t{\n\t\tpoint1,point2,point3,point1\n\t});\n\tvar isLineRing = polyLine1.IsLineRing;\n\n\tvar polyLine2 = new PolyLine(new List\u003cGeoPoint\u003e()\n\t{\n\t\tpoint4,point5\n\t});\n\t\n\tvar feature1 = new Feature(new Geometry(polyLine1));\n\tvar feature2 = new Feature(new Geometry(polyLine2));\n\n\tfs.Features.Add(feature1);\n\tfs.Features.Add(feature2);\n\tfs.Crs = Crs.Wgs84Gcs;\n\n\tvar dataTable = new DataTable();\n\tdataTable.Columns.Add(\"名称\", typeof(string));\n\tdataTable.Columns.Add(\"id\", typeof(int));\n\tvar row1 = dataTable.NewRow();\n\tvar row2 = dataTable.NewRow();\n\n\trow1[0] = \"线1\";\n\trow1[1] = 1;\n\n\trow2[0] = \"线2\";\n\trow2[1] = 2;\n\n\tdataTable.Rows.Add(row1);\n\tdataTable.Rows.Add(row2);\n\n\tfs.AttrTable = dataTable;\n\n\tfs.Save(\"../createNew/polyline.shp\");\n}\n\nvoid CreateMultiPolyLine()\n{\n\tIFeatureSet fs = new FeatureSet(FeatureType.PolyLine);\n\n\tvar point1 = new GeoPoint(132, 30);\n\tvar point2 = new GeoPoint(136, 30);\n\tvar point3 = new GeoPoint(134, 28);\n\tvar point4 = new GeoPoint(134, 32);\n\n\tvar polyLine1 = new PolyLine(new List\u003cGeoPoint\u003e()\n\t{\n\t\tpoint1,point2\n\t});\n\n\tvar polyLine2 = new PolyLine(new List\u003cGeoPoint\u003e()\n\t{\n\t\tpoint3,point4\n\t});\n\n\tvar multiPolyLine1 = new MultiPolyLine(new List\u003cPolyLine\u003e()\n\t{\n\t\tpolyLine1,polyLine2\n\t});\n   \n\tvar feature1 = new Feature(new Geometry(multiPolyLine1));\n\n\tfs.Features.Add(feature1);\n\tfs.Crs = Crs.Wgs84Gcs;\n\n\tvar dataTable = new DataTable();\n\tdataTable.Columns.Add(\"名称\", typeof(string));\n\tdataTable.Columns.Add(\"id\", typeof(int));\n\tvar row1 = dataTable.NewRow();\n\n\trow1[0] = \"十字多线\";\n\trow1[1] = 1;\n\n\tdataTable.Rows.Add(row1);\n\n\tfs.AttrTable = dataTable;\n\n\tfs.Save(\"../createNew/multiPolyLine.shp\");\n}\n\nvoid CreatePolygon()\n{\n\tIFeatureSet fs = new FeatureSet(FeatureType.Polygon);\n\n\tvar point1 = new GeoPoint(132, 30);\n\tvar point2 = new GeoPoint(136, 30);\n\tvar point3 = new GeoPoint(132, 35);\n\t\n\tvar edge = new PolyLine(new List\u003cGeoPoint\u003e()\n\t{\n\t\tpoint1, point2, point3, point1\n\t});\n\t\n\tvar polygon = new Polygon(edge);\n\n\t//edge，Clockwise\n\tvar point4 = new GeoPoint(140, 30);\n\tvar point5 = new GeoPoint(140, 35);\n\tvar point6 = new GeoPoint(150, 35);\n\tvar point7 = new GeoPoint(150, 30);\n\tvar edge2 = new PolyLine(new List\u003cGeoPoint\u003e()\n\t{\n\t\tpoint4, point5, point6, point7, point4\n\t});\n\n\t//points sketch \n\t//              .(point9)\n\t//\n\t//  .(point8)          .(point10)\n\t//\n\tvar point8 = new GeoPoint(142, 31);\n\tvar point9 = new GeoPoint(145, 33);\n\tvar point10 = new GeoPoint(148, 31);\n\n\t//hole, need Counterclockwise,\n\t//if Counterclockwise, sequence should be:\n\t//point8, point10, point9\n\t//It will be handled inside the library.\n\t//It will be a line ring inside the library too\n\tvar hole = new PolyLine(new List\u003cGeoPoint\u003e()\n\t{\n\t\tpoint8,point9,point10\n\t});\n\tvar polygon2 = new Polygon(edge2, hole);\n\n\n\tvar feature1 = new Feature(new Geometry(polygon));\n\tvar feature2 = new Feature(new Geometry(polygon2));\n\n\tfs.Features.Set(new List\u003cIFeature\u003e()\n\t{\n\t\tfeature1,\n\t\tfeature2\n\t});\n\tfs.Crs = Crs.Wgs84Gcs;\n\n\n\tvar dataTable = new DataTable();\n\tdataTable.Columns.Add(\"名称\", typeof(string));\n\tdataTable.Columns.Add(\"id\", typeof(int));\n\tvar row1 = dataTable.NewRow();\n\tvar row2 = dataTable.NewRow();\n\n\trow1[0] = \"简单面\";\n\trow1[1] = 1;\n\n\trow2[0] = \"带洞面\";\n\trow2[1] = 2;\n\n\tdataTable.Rows.Add(row1);\n\tdataTable.Rows.Add(row2);\n\n\tfs.AttrTable = dataTable;\n\n\tfs.Save(\"../createNew/polygon.shp\");\n}\n\n//for using GB2312\nEncoding.RegisterProvider(CodePagesEncodingProvider.Instance);\n\nCreatePoint();\nCreateMultiPoint();\nCreatePolyLine();\nCreateMultiPolyLine();\nCreatePolygon();\n```\nCorespatial refers to **DotSpatial**. Some of its usage is similar. See CoreSpatial.Test for details.\n\nConvert to GeoJSON (You need to add reference **CoreSpatial.Converter** first):\n```c#\nfs.ToGeoJSON();\n```\n\nConvert to KML/KMZ (You need to add reference **CoreSpatial.Converter** first):\n```c#\nfs.ToKML(kmlName);\nfs.ToKMZ(kmlName, KmzSavePath);\n```\n\nSee CoreSpatial.Converter.Test for usage, Geojson can be verified at http://geojson.io/.\n\n\n### Attention\n+ Cannot read SHP file of M value and Z value\n\n### Reference \n[DotSpatial](https://github.com/DotSpatial/DotSpatial \"DotSpatial\")\n\n[NetTopologySuite.IO.ShapeFile](https://github.com/NetTopologySuite/NetTopologySuite.IO.ShapeFile \"NetTopologySuite.IO.ShapeFile\")\n\n\n### Developer\nzxyao145\n\n### License\nSee LICENSE.txt\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzxyao145%2Fcorespatial","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzxyao145%2Fcorespatial","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzxyao145%2Fcorespatial/lists"}