1.å¦ä½ä½¿ç¨nettopologysuite
å¦ä½ä½¿ç¨nettopologysuite
ä¸é¢æ¯ä¸ä¸ªç®åçä¾åï¼æ¼ç¤ºäºå¦ä½ä¸ºShapeæ件è¿è¡ç¼å²åºåæï¼
public void InitializeMap(SharpMap.Map map)
{
//å建Shapeæ件çæ°æ®æº
SharpMap.Data.Providers.ShapeFile shp = new SharpMap.Data.Providers.ShapeFile("rivers.shp",源码genericservlet 源码 true);
//å建NTSæ°æ®æºï¼ä»Shapeæ件è·åæ°æ®ï¼ç¶åè°ç¨NtsOperationæ¹æ³
SharpMap.Data.Providers.NtsProvider nts = new SharpMap.Data.Providers.NtsProvider(shp,new SharpMap.Data.Providers.NtsProvider.GeometryOperationDelegate(NtsOperation));
//å建渲æå¾å±
SharpMap.Layers.VectorLayer layRivers = new SharpMap.Layers.VectorLayer("Rivers");
layRivers.DataSource = nts;
layRivers.Style.Fill = Brushes.Blue;
map.Layers.Add(layRivers);
}
//å®ä¹ä¸ä¸ªç¼å²åºåæçå§æ
public static void NtsOperation(List<GisSharpBlog.NetTopologySuite.Features.Feature> geoms)
{
foreach (GisSharpBlog.NetTopologySuite.Features.Feature f in geoms)
f.Geometry = f.Geometry.Buffer(0.5);
}
ä»ä¸é¢çä¾åï¼æ们å¯ä»¥çå°ï¼éè¿.netçå§æï¼ä½¿ç¨NTS Data Providerï¼å¯ä»¥å¨SharpMapä¸ä½¿ç¨NTSç空é´åææ¹æ³ã
SharpMapçä½è Morten Nielsenå¨Blogä¸ä¹ç»åºäºå¦ä½å¨SharpMapä¸ä½¿ç¨NTSçä¾åï¼
1. 对å ä½å¯¹è±¡è¿è¡ç©ºé´åæï¼æ¬ç¤ºä¾æ¯ç¼å²åºåæï¼
é¦å å建ä¸ä¸ªNTSçæ°æ®æºï¼ä»£è¡¨è¦è¿è¡ç©ºé´åæçæ°æ®ï¼å ¶ä¸myShapeFileDatasource代表ä¸ä¸ªShapeæ件çæ°æ®æºï¼åå ä¸é¢ç示ä¾ï¼ï¼
NtsProvider ntsDataSource = new NtsProvider(myShapeFileDatasource, CreateBuffers);
å建ç¼å²åºï¼
private void CreateBuffers(List<GisSharpBlog.NetTopologySuite.Features.Feature> features)
{
foreach (GisSharpBlog.NetTopologySuite.Features.Feature feature in features)
feature.Geometry = feature.Geometry.Buffer(0.5);
}
2. 使ç¨NTSå精确ç交éå¤æï¼æ¬ç¤ºä¾éè¿ç¹å»ï¼é«äº®éæ©å¯¹è±¡ï¼è¿åç¸åºçå±æ§ã
å¯ä»¥ä½¿'ntsDataSource'对象æåä¸ä¸ªç¢éå¾å±å¯¹è±¡ï¼vectorlayerï¼ï¼ç¹å»å¹¶é«äº®éæ©å¯¹è±¡ãå¯ä»¥éè¿ImageButton (ASP.NET)æè PictureBox (Windows.Forms)çç¹å»äºä»¶ï¼Click-Eventï¼æ¥è§¦åçï¼
protected void imgMap_Click(object sender, ImageClickEventArgs e)
{
//转æ¢å¾å½¢åæ å°å°å¾åæ
Point ClickPnt = myMap.ImageToWorld(new System.Drawing.Point(e.X, e.Y));
SharpMap.Data.FeatureDataSet ds = new SharpMap.Data.FeatureDataSet();
//å¨ç¬¬ä¸å±è¿è¡æ¥è¯¢ï¼æ³¨æ使ç¨äºNTSçExecuteIntersectionQueryæ¹æ³
(myMap.Layers[0] as SharpMap.Layers.VectorLayer).DataSource.ExecuteIntersectionQuery(ClickPnt, ds);
if (ds.Tables.Count > 0) //å¾å°äºç»æ
{
//å¢å ç¹å»éæ©ç对象å°selectionå¾å±
//è¿æ ·å°±æ°å¢äºä¸ä¸ªå¾å±ï¼å æ¤æ¸²æ该å¯å°å¾åæ¾ç¤ºéä¸å¯¹è±¡
SharpMap.Layers.VectorLayer laySelected = new SharpMap.Layers.VectorLayer("Selection");
laySelected.DataSource = new GeometryProvider(ds.Tables[0]);
laySelected.Style.Fill = new System.Drawing.SolidBrush(System.Drawing.Color.Yellow);
myMap.Layers.Add(laySelected);
}
//渲æå°å¾
GenerateMap();
}
è¿æ ·ï¼åªè¦ç¹å»å°å¾ï¼å°±ä¼éæ©å¹¶é«äº®éä¸å¯¹è±¡ã
2024-11-23 12:24
2024-11-23 11:52
2024-11-23 11:50
2024-11-23 11:37
2024-11-23 11:33
2024-11-23 10:50
2024-11-23 10:21
2024-11-23 10:16