SharpMap官方教程.docx

上传人:b****2 文档编号:3246046 上传时间:2023-05-05 格式:DOCX 页数:29 大小:109.46KB
下载 相关 举报
SharpMap官方教程.docx_第1页
第1页 / 共29页
SharpMap官方教程.docx_第2页
第2页 / 共29页
SharpMap官方教程.docx_第3页
第3页 / 共29页
SharpMap官方教程.docx_第4页
第4页 / 共29页
SharpMap官方教程.docx_第5页
第5页 / 共29页
SharpMap官方教程.docx_第6页
第6页 / 共29页
SharpMap官方教程.docx_第7页
第7页 / 共29页
SharpMap官方教程.docx_第8页
第8页 / 共29页
SharpMap官方教程.docx_第9页
第9页 / 共29页
SharpMap官方教程.docx_第10页
第10页 / 共29页
SharpMap官方教程.docx_第11页
第11页 / 共29页
SharpMap官方教程.docx_第12页
第12页 / 共29页
SharpMap官方教程.docx_第13页
第13页 / 共29页
SharpMap官方教程.docx_第14页
第14页 / 共29页
SharpMap官方教程.docx_第15页
第15页 / 共29页
SharpMap官方教程.docx_第16页
第16页 / 共29页
SharpMap官方教程.docx_第17页
第17页 / 共29页
SharpMap官方教程.docx_第18页
第18页 / 共29页
SharpMap官方教程.docx_第19页
第19页 / 共29页
SharpMap官方教程.docx_第20页
第20页 / 共29页
亲,该文档总共29页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

SharpMap官方教程.docx

《SharpMap官方教程.docx》由会员分享,可在线阅读,更多相关《SharpMap官方教程.docx(29页珍藏版)》请在冰点文库上搜索。

SharpMap官方教程.docx

SharpMap官方教程

HowtogetSharpMapsourcecode

V0.9/1.0

Youhavetwochoices:

1.DownloadfromCodePlex

1.Clickonthe"SourceCode"tab

2.Click"Download"inthe"LatestVersion"frame.

3.Acceptthelicenseagreementandpickaplacetosaveazip-fileofthecurrentversion,unpack.

4.Opensolutionandcompile.

2.Usesubversionclient(TortoiseSVN)

1.GetyouselfacopyofTortoiseSVNandinstall.

2.OpenExplorer,chooseplacetosaveyourcopyofSharpMap,andright-clickthemouse.

3.Fromthecontext-menuchoose"checkout"andfillinthefollowingurl:

*)andmaybechangethedestinationpath.Usernameandpasswordarethesameasonthecodeplexsite.

4.Opensolutionfileandcompile.

*)ThereareseveralbranchesforSharpMap

URL

Description

IntegrationofNetTopologySuitev1.7

Heavilyextendedv0.9.5version

PartialcloneofTrunkforaddingGeoJSONsupport(incorporatedinTrunk,maybedeletedsoon?

anexperimentalbranchfeaturingasyncrenderingandafewotherexperiments.Avoid

Iscurrentlybeeingdevelopedon

DONOTUSE,seebelow

BugFixbranchofuserBenjii

IntegrationofNTSv1.12(workinprogress)

V2.0

Thisversionisbeingdevelopedon

Latestprojectupdates

1.GetyouselfacopyofTortoiseSVNandinstall.

2.OpenExplorer,chooseplacetosaveyourcopyofSharpMap,andright-clickthemouse.

3.Fromthecontext-menuchoose"checkout",fillinthefollowingurl:

**)andmaybechangethedestinationpath.Leaveusernameandpasswordblank.

4.Opensolutionfileandcompile.

**)ThereareseveralbranchesforSharpMap

URL

Description

Gdal-,Ogr-andBrutileProvider

LasteditedDec202011at6:

20PM by FObermaier,version10

HowdoIcreateamap?

Initializethemap,addlayers,setupstyleandrenderit:

SharpMap.MapmyMap=newSharpMap.Map(newSize(400,300));

myMap.Size=newSystem.Drawing.Size(300,200);//Setoutputsize

myMap.MinimumZoom=100;//Minimumzoomallowed

myMap.BackgroundColor=Color.White;//Setbackground

myMap.Center=newSharpMap.Geometry.Point(725000,6180000);//Setcenterofmap

//AddPostGISlayer:

SharpMap.Layers.VectorLayermyLayer=newSharpMap.Layers.VectorLayer("Mylayer");

stringConnStr="Server=127.0.0.1;Port=5432;UserId=postgres;Password=password;Database=myGisDb;";

myLayer.DataSource=newSharpMap.Data.Providers.PostGIS(ConnStr,"myTable","the_geom",32632);

myLayer.MaxVisible=40000;

myMap.Layers.Add(myLayer);

//Renderthemap

////1stpossibility:

Setzoomlevel

//myMap.Zoom=1200;//Setzoomlevel

//2nd.possibility:

Zoomtoextents

myMap.ZoomToExtents();

System.Drawing.ImageimgMap=myMap.GetMap();

Note:

SharpMap.Data.Providers.PostgisismemberoftheSharpMap.Extensionsproject.

LasteditedMar92010at6:

24AM by FObermaier,version6

Transformingbetweenimagecoordinatesandworldcoordinates

SharpMaphasbuilt-infunctionstohelpyoutransformbetweenimageandworldcoordinates.

Whentheuserclicksthemapatagivenpixel(x,y),youcantranslatethisworldcoordinatesusingtheImageToWorldmethod:

SharpMap.Geometries.Pointp=myMap.ImageToWorld(newSystem.Drawing.PointF(x,y));

Pleasenotethatthevalueiscalculatedbasedonthecurrentzoomandcenter-valuesofthemyMapMapobject.

Ifyouwanttodotheoppositetransformation,useWorldToImage:

System.Drawing.PointFp=myMap.WorldToImage(newSharpMap.Geometries.Point(34.225,175.432));

LasteditedAug242007at9:

24AM by rstuven,version6

Creatingaclickablemap

System.Windows.Forms

1.InsertaPictureBoxforWindows.Forms.

2.Settheimagetoyourmap-instance.Ex.:

imgMap.Image=myMap.GetMap();

3.SetupaMouseClick-eventforyourPictureBox.

4.CreateaMouseClick-eventhandler,similartotheonebelow.

protectedvoidimgMap_MouseClick(objectsender,MouseClickEventArgse)

{

//Centerthemapontheclick-point

myMap.Center=myMap.ImageToWorld(newSystem.Drawing.PointF(e.X,e.Y),myMap);

//Zoomin2x

myMap.Zoom*=0.8;

//Callfunctionthatrendersthemapandreturnsittotheclient

myImage.Image=myMap.GetMap();

}

Thereareready-to-useUserControls(MapImage/MapBox)intheSharpMap.UIproject.Inadditiontozoomingfunctionalitytheyoffertoolsforqueryingandpanning.

ASP.NET

1.Insertan

ImageButton>forASP.NETwebforms.

2.Settheimagetoyourmap-instance.Ex.:

imgMap.Image=myMap.GetMap();

3.Setupaclick-eventforyourImageButton.

4.Createaclick-eventhandler,similartotheonebelow.

protectedvoidimgMap_Click(objectsender,ImageClickEventArgse)

{

//Centerthemapontheclick-point

myMap.Center=myMap.ImageToWorld(newSystem.Drawing.PointF(e.X,e.Y),myMap);

//Zoomin2x

myMap.Zoom*=0.8;

//Callfunctionthatrendersthemapandreturnsittotheclient

myImage.Image=myMap.GetMap();

}

Note:

Youneedtostorethezoomandcentervaluesbetweenrequests.ThiscanbedoneusingeitherViewStateorSessionvariables.Theseshouldberestoredonapostback,andstoredwhentheyarechanged.

LasteditedSep12010at6:

19PM by FObermaier,version11

HowdoIaddaWMSlayer?

TheWMSLayersupportiscurrentlyprettybasic.Youwillhavetodeciphertheservercapabilitiesyourself,andspecifythenessesarylayersandotherpropertiesintheresourceproperty.

Here'sanexampleofhowtoaddtheDemisWMSserver:

stringwmsUrl="http:

//www2.demis.nl/mapserver/request.asp";

SharpMap.Layers.WmsLayerlayWms=newSharpMap.Layers.WmsLayer("DemisMap",wmsUrl);

layWms.SpatialReferenceSystem="EPSG:

4326";//Setspatialreferencetouseforthisservice

//Addlayers(browsetheRootLayer/ChildLayerscollectiontofindavailable/validlayernames)

layWms.AddLayer("Bathymetry");

layWms.AddLayer("Countries");

layWms.AddLayer("Rivers");

layWms.AddLayer("Oceanfeatures");

//Setimageformattorequestfromserver

//SeelayWms.OutputFormatsarrayforformatssupportedbythisWMS

layWms.SetImageFormat("image/png");

//SkiprenderingtheWMSMapiftheservercouldn'tberequested

//Ifsettofalsesuchaneventwouldcrashtheapp.

layWms.ContinueOnError=true;

layWms.TimeOut=5000;//Settimeoutto5seconds

myMap.Layers.Add(layWms);//Addlayertoyourmap'slayercollection

Youcangetanexampleofhowanimagerequestwouldlooklike,byusingtheGetRequestUrlmethod.ThisisalsogoodfordebuggingtheWMSserver,sincetheserveroftenreturnsanerrormessageoninvalidrequests.

stringimageUrl=layWms.GetRequestUrl(newBoundingBox(0,0,360,180),newSize(600,300));

LasteditedAug92006at5:

46AM by SharpGIS,version5

HowdoIaddashapefilelayer?

UsetheShapeFileProvider:

SharpMap.Layers.VectorLayerlayWorld=newSharpMap.Layers.VectorLayer("World");

//Specifingtruewillsavethespatialindextoafilewhichwillmakeitloadquickerthenexttime

layWorld.DataSource=newSharpMap.Providers.ShapeFile(@"C:

\Data\Countries.shp",true);

myMap.Layers.Add(layWorld);

LasteditedAug42006at12:

55AM by SharpGIS,version6

HowtoaddaPostGISdatasourcetotheMap

ThePostGISproviderisusedforrenderinggeometrydatafromanPostGreSQLdatabase.YouwillneedtoinstallthePostGISextensioninPostGreSQLtouseitwithSharpMap.

Togetproperperformance,makesureyouhaveappliedaspatialindextothegeometrycolumn.

stringconnStr="Server=127.0.0.1;Port=5432;UserId=postgres;Password=pass;Database=myMapDB";//Connectionstring

stringtablename="Roads";//Nameoftableindatabase

stringidColumn="gid";//NameofobjectIDcolumn-MUSTbeinteger!

SharpMap.MapmyMap=newSharpMap.Map(newSystem.Drawing.Size(500,250));//Initializemapobject

SharpMap.Layers.VectorLayerlayRoads=newSharpMap.Layers.VectorLayer("Roads");//Createlayer

layRoads.DataSource=newSharpMap.Providers.OleDbPoint(connStr,tablename,gid);//SetthedatasourcetothePostGreSQLtable

myMap.Layers.Add(layRoads);//Addlayertomap

myMap.ZoomToExtents();//Zoomtoextents

Imageimg=myMap.GetMap();//Rendermap

YoucanfindmorehelpatthePostGISwebsiteonhowtoloadmapdataintothePostGreSQLdatabase,andhowtoinstallPostGISproperlyonyoudatabase.

Note:

InearlierversionsPostGISwasincludedinSharpMap,butisnowaseperateextensionthatneedstobeaddedtoSharpMap.SeePostGIS

LasteditedAug42006at1:

16AM by SharpGIS,version3

ThisexampleisderiviedfromtheAddaPostGISlayerexample.

stringtablename="Roads";//Nameoftableindatabase

stringidColumn="gid";//NameofobjectIDcolumn-MUSTbeinteger!

SharpMap.MapmyMap=newSharpMap.Map(newSystem.Drawing.Size(500,250));//Initializemapobject

SharpMap.Layers.VectorLayerlayRoads=newSharpMap.Layers.VectorLayer("Roads");//Createlayer

layRoads.DataSource=newSharpMap.Providers.OleDbPoint(connStr,tablename,gid);//SetthedatasourcetothePostGreSQLtable

 

//Setuparoadlabellayer

SharpMap.Layers.LabelLayerlayRoadLabel=newSharpMap.Layers.LabelLayer("Roadlabels");

layRoadLabel.DataSource=layRoads.DataSource;

layRoadLabel.Enabled=true;

layRoadLabel.LabelColumn="RoadOfNa

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 解决方案 > 学习计划

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2