I have lat and long values:
lat : 126.882635295
long: 37.4799670597
How can I find this location from map?
I need to find location and make marker on it in the map.
Thank You
I have lat and long values:
lat : 126.882635295
long: 37.4799670597
How can I find this location from map?
I need to find location and make marker on it in the map.
Thank You
(1) find location
SetGeographicExtents2() method may help you.
(2) make marker
you can add point shapefile, choose point style to make marker.
https://www.mapwindow.org/documentation/mapwingis4.9/_mark_points_8cs-example.html
I have lat and long values but I don’t have widthKilometers value.
Do you know values of widthKilometers parameter?
Hello Kayumiy
widthKilometers
is an input value. It is up to you. You are defining the visual extents of your screen. So the screen will be centered at xLongitude and yLatitude, and the effective width of your screen will be widthKilometers wide (in other words, the number you provide is how many kilometers the view will be).
I hope that makes sense.
Jerry.
This is the output result.
I don’t know why SetGeographicExtents2 method always returns false.
My objective is that I need to find location based on lat and long values and put marker icon on this location.
Can you guide me please?
Thank You
I looked at the source code, and it turns out that the function erroneously always returns FALSE. However, it may still be doing the right thing. Is it properly locating the position on the map? It looks like it is.
I will have to submit a change to the source code.
Thank you.
https://www.mapwindow.org/documentation/mapwingis4.9/_mark_points_8cs-example.html
This link above does not explain how to ass marker based on lat and long values.
Is there any another way?
Sorry I don’t understand what you mean “I will have to submit a change to the source code.”
Hello @Kayumiy
Regarding the sample to add a marker, take the code from the MouseDown event. The only difference is that instead of using the mouse point, you would use your lon, lat.
Assuming you have a shapefile reference, do something like the following:
Shape shp = new Shape;
shp.Create(ShpfileType.SHP_POINT);
Point pnt = new Point();
pnt.x = <yourLonValue>;
pnt.y = <yourLatValue>;
int index = shp.numPoints;
shp.InsertPoint(pnt, ref index);
index = sf.NumShapes;
if (sf.StartEditing())
{
if (!sf.EditInsertShape(shp, ref index))
{
MessageBox.Show("Failed to insert shape: " + sf.get_ErrorMsg(sf.LastErrorCode);
return;
}
sf.StopEditShapes();
axMap1.Redraw();
}
Regarding my comment that I have to submit a change to the source code, don’t worry about that. Since I found a bug in the OCX code, I will fix it and submit it for the next release. But it does not affect what you are doing.
Regards,
Jerry.
Hello,
I have an error after applying your code:
This is whole code:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Shapefile shapefile1;
Shapefile shapefile2;
int intHandler1;
int intHandler2;
private void Form1_Load(object sender, EventArgs e)
{
//MapWinGIS.Shapefile is a data provider for ESRI Shapefile
shapefile1 = new Shapefile();
shapefile2 = new Shapefile();
//Define the data source for MapWinGIS.Shapefile instance
shapefile1.Open(@"C:\Users\User\Downloads\CH_00_D002_20200512\CH_00_D002_20200512.shp", null);
//display the layer on the map
intHandler1 = axMap1.AddLayer(shapefile1, true);
intHandler2 = axMap1.AddLayer(shapefile2, true);
MakeMarker(); // line 42
}
public void MakeMarker()
{
shapefile2 = axMap1.get_Shapefile(intHandler2);
Shape shp = new Shape();
shp.Create(ShpfileType.SHP_POINT);
Point pnt = new Point();
double x = 37.4799670597;
double y = 126.882635295;
pnt.x = x;
pnt.y = y;
int index = shp.numPoints;
shp.InsertPoint(pnt, ref index);
index = shapefile2.NumShapes; // line 57
if (shapefile2.StartEditingShapes())
{
if (!shapefile2.EditInsertShape(shp, ref index))
{
MessageBox.Show("Failed to insert shape: " + shapefile2.get_ErrorMsg(shapefile2.LastErrorCode));
return;
}
shapefile2.StopEditingShapes();
axMap1.Redraw();
}
}
}
This is code line to find
MakeMarker(); // line 42
index = shapefile2.NumShapes; // line 57
Hello.
One thing to do is to set up your shapefile as a Point-based shapefile by calling CreateNew, as follows:
// create an empty Shapefile instance
shapefile2 = new Shapefile();
// sets up an in-memory shapefile without a name
shapefile2.CreateNew("", ShpfileType.SHP_POINT);
This should hopefully resolve your problem.
Jerry.
Hello again.
I should also mention that since you are not setting up any specific Drawing Options, you will likely just get a default dot on the screen. If you want a specific marker symbol, you will have to set that up using the DefaultDrawingOptions property of the Shapefile.
Regards.
That is strange. If we are creating a Shapefile of type POINT, and then attempting to insert a POINT, we should not get the “incompatible Shapefile Type” error.
Now I do notice that your X and Y need to be swapped. The X-value is the longitude, and should be 126 and the Y-value is the latitude, and should be 37. Otherwise, the Y is out of range.
Try exchanging X and Y and see if that works. If not, please post the entire program again.
Thank you.
double x = 126.882635295;
double y = 37.4799670597;
double X = 0.0;
double Y = 0.0;
//axMap1.PixelToProj(126.882635295, 37.4799670597, ref x, ref y);
axMap1.DegreesToProj(x, y, ref X, ref Y);
I used DegreesToProj method. It converts coordinates in decimal degrees to projected map coordinates. Now, it works.
Thank You for your great effort and help Sir.
You’re welcome. I’m glad it’s working now.
Regards,
Jerry.
I am sorry I forgot to tell you.
I have changed entire source-code.
I deleted all and used MarkPoints.cs example script.
I changed 3 things:
Then all works fine.