Hi,
I have a function that gets XY data from a datagridview and then plot the points on a map. I want to change the point size and add labels, but my code only change the size of 1 points and add correct label for 1 point too (all other points are labeled "0").
My code:
Image may be NSFW.
Clik here to view.
Anyone have an idea why it is happening ?
Thanks !
I have a function that gets XY data from a datagridview and then plot the points on a map. I want to change the point size and add labels, but my code only change the size of 1 points and add correct label for 1 point too (all other points are labeled "0").
My code:
var sf = new Shapefile();
// MWShapeId field will be added to attribute table
sf.CreateNewWithShapeID("", ShpfileType.SHP_POINT);
var rows = dgv.SelectedRows;
int idx = 0;
foreach (DataGridViewRow row in rows)
{
string raw_x = row.Cells[dgv.Columns["x_coord"].Index].Value.ToString();
string raw_y = row.Cells[dgv.Columns["y_coord"].Index].Value.ToString();
double value = Convert.ToDouble(row.Cells[dgv.Columns["value"].Index].Value);
int field_idx = sf.EditAddField("value", FieldType.DOUBLE_FIELD, 0, 10);
var pnt = new Point();
pnt.x = Convert.ToDouble(raw_x);
pnt.y = Convert.ToDouble(raw_y);
Shape shp = new Shape();
shp.Create(ShpfileType.SHP_POINT);
shp.InsertPoint(pnt, 0);
sf.EditInsertShape(shp, ref idx);
sf.EditCellValue(field_idx, idx, value);
idx++;
}
var sc_id = rows[0].Cells[dgv.Columns["sc_uid"].Index].Value.ToString();
// get projection in database
string getProjection = String.Format("select proj_zoneutm from projects " +
"inner join results on projects.proj_num = results.proj_num " +
"where sc_uid = '{0}';", sc_id);
List<string> proj = new List<string>();
NpgsqlDataReader data = dbConn.ExecuteReader(getProjection);
while (data.Read()) {
proj.Add(data.GetString(0));
}
var gp = new GeoProjection();
gp.ImportFromEPSG(Convert.ToInt16(proj[0]));
axMap1.GeoProjection = gp;
sf.DefaultDrawingOptions.SetDefaultPointSymbol(tkDefaultPointSymbol.dpsCircle);
// call function to create categories and add color scheme
sf = CreateCategories(sf, "value");
// generate labels for field "value"
sf.Labels.Generate("[value]", tkLabelPositioning.lpInteriorPoint, true);
var lyr_hdl = axMap1.AddLayer(sf, true);
axMap1.set_ShapeLayerPointSize(lyr_hdl, 20);
axMap1.ZoomToMaxExtents();
// save if needed
//sf.SaveAs(@"c:\points.shp", null);
}
Here is the results on the map:Image may be NSFW.
Clik here to view.

Anyone have an idea why it is happening ?
Thanks !