mymap PROJECT,POLYGON SELECTION,LAYER

Topics: SharpMap Project
Jul 2, 2008 at 10:31 AM
HI............

a very healthy afternoon to all of u!!

help help help!!

hi.......treiuvy nd everybdy.....

thanx 4 all the help....
here is my project's code.....m new to c#.net......plz help....

MOTO OF MY PROJECT:
1- USER CAN SELECT /UNSELECT THE LAYERS TO VIEW BY HIS CHOICE USING CHECKBOXES.......
2-FOR "COUNTRIESLAYER".....HE CAN SELECT A PARTICULAR POLYGON AND SHOW THE INFORMATION ABOUT THE COUNTRY USIN A POP-UP!!


plz help me ............completing my project...last day of submission is monday......
m in need!!



<code>
using System;

 

 

 

 

using

System.Collections.Generic;

 

 

 

 

using

System.ComponentModel;

 

 

 

 

using

System.Data;

 

 

 

 

using

System.Drawing;

 

 

 

 

using

System.Text;

 

 

 

 

using

System.Windows.Forms;

 

 

 

 

using

SharpMap;

 

 

 

 

using

GeoAPI.Geometries;

 

 

 

 

 

 

namespace

Map1

 

{

 

public partial class Form1 : Form

 

 

 

 

{

 

SharpMap.

Map myMap1;

 

 

 

//define dataname and source

 

 

 

 

 

public int a;

 

 

public int b;

 

 

const string data_name1 = "world countries";

 

 

const string data_path1 = @"I:\downloads\SharpMap-3316412\Branches\1.1experimental\WinFormSamples\GeoData\World\countries.shp";

 

 

const string data_name2 = "cities";

 

 

const string data_path2 = @"I:\downloads\SharpMap-3316412\Branches\1.1experimental\WinFormSamples\GeoData\World\cities.shp";

 

 

const string data_name3 = "rivers";

 

 

const string data_path3 = @"I:\downloads\SharpMap-3316412\Branches\1.1experimental\WinFormSamples\GeoData\World\rivers.shp";

 

 

const string data_path4 = @"I:\downloads\railroad\railroads.shp";

 

 

 

public Form1()

 

{

InitializeComponent();

 

 

 

//ADD the counties shape file to the map

 

 

 

 

 

//countries------

 

 

 

 

SharpMap.Layers.

VectorLayer countrieslayer = new SharpMap.Layers.VectorLayer(data_name1);

 

countrieslayer.DataSource =

new SharpMap.Data.Providers.ShapeFile(data_path1);

 

 

//cities--------

 

 

 

 

SharpMap.Layers.

VectorLayer citieslayer = new SharpMap.Layers.VectorLayer(data_name2);

 

citieslayer.DataSource =

new SharpMap.Data.Providers.ShapeFile(data_path2);

 

 

//river--------

 

 

 

 

SharpMap.Layers.

VectorLayer riverlayer = new SharpMap.Layers.VectorLayer(data_name3);

 

riverlayer.DataSource =

new SharpMap.Data.Providers.ShapeFile(data_path3);

 

 

 

 

//map is a gloabal variable which type is "Map"

 

 

 

 

 

//initialize the map

 

 

 

 

myMap1 =

new SharpMap.Map(new Size(400, 600));

 

myMap1.BackColor =

Color.Aqua;

 

myMap1.Layers.Add(countrieslayer);

myMap1.Layers.Add(riverlayer);

myMap1.Layers.Add(citieslayer);

 

 

//set a dash pattern

 

 

 

 

myMap1.ZoomToExtents();

 

//set color to green......

 

 

 

 

countrieslayer.Style.Fill =

new SolidBrush(Color.Bisque);

 

 

//set borders to color black

 

 

 

 

countrieslayer.Style.Outline = System.Drawing.

Pens.Black;

 

countrieslayer.Style.EnableOutline =

true;

 

riverlayer.Style.Line = System.Drawing.

Pens.White;

 

citieslayer.Style.Line = System.Drawing.

Pens.Wheat;

 

 

SharpMap.Data.

FeatureDataRow rowselected = FindGeoNearPoint(Mouse_Click(a,b), countrieslayer, 50);  / /HOW TO DEAL WID THS MOUSE CLICK

 

myMap1.Center =

new SharpMap.Geometries.Point(0, 0);

 

SharpMap.Layers.

VectorLayer laySelected = new SharpMap.Layers.VectorLayer("Selection");

 

laySelected.DataSource =

new SharpMap.Data.Providers.GeometryProvider(rowselected.Geometry);

 

laySelected.Style.Fill =

new System.Drawing.SolidBrush(SystemColors.Highlight);

 

myMap1.Layers.Add(laySelected);

 

 

}

 

 

 

private void worldCountriesToolStripMenuItem_Click(object sender, EventArgs e)

 

{

 

if (ofd.ShowDialog() == DialogResult.OK)

 

{

 

if (ofd.FileName == data_path1)

 

{

pictureBox1.Visible =

true;

 

pictureBox1.Image = myMap1.GetMap();

checkBox1.Visible =

true;

 

checkBox1.Checked =

true;

 

checkBox2.Visible =

true;

 

checkBox2.Checked =

true;

 

checkBox3.Visible =

true;

 

checkBox3.Checked =

true;

 

}

}

}

 

private void Form1_Load(object sender, EventArgs e)

 

{

 

if (checkBox2.Checked == false)

 

{

//wat do i write here.....so that a particular layer can be visible or not BY USER'S CHOICE.
}

}

 

 

private void Mouse_Click(object sender, MouseEventArgs e)

 

{

 

 

}

 

 

public SharpMap.Data.FeatureDataRow FindGeoNearPoint(SharpMap.Geometries.Point pos, SharpMap.Layers.VectorLayer layer, double amountGrow)

 

{

SharpMap.Geometries.

BoundingBox bbox = pos.GetBoundingBox().Grow(amountGrow);

 

SharpMap.Data.

FeatureDataSet ds = new SharpMap.Data.FeatureDataSet();

 

layer.DataSource.ExecuteIntersectionQuery(bbox, ds);

 

DataTable tbl = ds.Tables[0] as SharpMap.Data.FeatureDataTable;

 

GisSharpBlog.NetTopologySuite.IO.

WKTReader reader = new GisSharpBlog.NetTopologySuite.IO.WKTReader();

 

GeoAPI.Geometries.

IGeometry point = reader.Read(pos.ToString());

 

 

if (tbl.Rows.Count == 0)

 

 

return null;

 

 

 

double distance = point.Distance(reader.Read((tbl.Rows[0] as SharpMap.Data.FeatureDataRow).Geometry.ToString()));

 

SharpMap.Data.

FeatureDataRow selectedFeature = tbl.Rows[0] as SharpMap.Data.FeatureDataRow;

 

 

if (tbl.Rows.Count > 1)

 

 

for (int i = 1; i < tbl.Rows.Count; i++)

 

{

GeoAPI.Geometries.

IGeometry line = reader.Read((tbl.Rows[i] as SharpMap.Data.FeatureDataRow).Geometry.ToString());

 

 

if (point.Distance(line) < distance)

 

{

distance = point.Distance(line);

selectedFeature = tbl.Rows[i]

as SharpMap.Data.FeatureDataRow;

 

}

}

 

return selectedFeature;

 

}

 

  }

}

Jul 3, 2008 at 7:55 AM

<code>
public

System.EventArgs ImageClickEventArgs;
<code>

<code>
protected void imgMap_Click(object sender,ImageClickEventArgs e)

 

{

 

//Center the map on the click-point

 

 

 

myMap1.Center = myMap1.ImageToWorld(

new System.Drawing.PointF(e.X, e.Y), myMap1);

 

 

//Zoom in 2x

 

 

 

myMap1.Zoom *= 0.5;

 

//Call function that renders the map and returns it to the client

 

 

 

myImage.Image = myMap.GetMap();

}
<code>