create point with feature data

Apr 7, 2010 at 12:28 PM
Edited Apr 7, 2010 at 4:38 PM

hi

i looking for a way to add point on map with a feature data.

 there is a way to create featuredataset and set this geometry to a point ?.

i succed to write that code to create a shapefile but i want a featuredataset

 

 DataSet dsSecteur = mySqlCartoData.GetPositionBatiment("batiment");                            
 List<Feature> features = new List<Feature>();

foreach (DataRow drPoint in dsSecteur.Tables[0].Rows)
{               
   string X = drPoint["X"].ToString().Replace(".", ",");
   string Y = drPoint["Y"].ToString().Replace(".", ",");

   if (!string.IsNullOrEmpty(X) && !string.IsNullOrEmpty(X))
   {
       mtmCoordinate[0] = double.Parse(X);
       mtmCoordinate[1] = double.Parse(Y);
   }

   if (mtmCoordinate[0] != mtmCoordinate[1] && mtmCoordinate[0] != 0)
   {
                    //Convert mtm Coordinate[ to log lat
      double[] lonlatCoordinate = MercatorToWgs84LatLon(mtmCoordinate);
      drPoint["X"] = lonlatCoordinate[0];
      drPoint["Y"] = lonlatCoordinate[1];

      GeoAPI.Geometries.IGeometry point = new GisSharpBlog.NetTopologySuite.Geometries.Point(lonlatCoordinate[0], lonlatCoordinate[1]);

      Feature feature = new Feature(point, new AttributesTable());
                                      
      foreach (DataColumn dC in dsSecteur.Tables[0].Columns)
      {
         feature.Attributes.AddAttribute(dC.ColumnName, drPoint[dC.ColumnName]);                       
      } 
                                                                
      features.Add(feature);                    
   }                       

 

Coordinator
Apr 7, 2010 at 1:53 PM

hello longuard,

the code you posted uses NetTopologySuite classes.

If you want to render your data using SharpMap, the probably easiest way to proceed is to derive a MySqlSpatial provider from one of the existing Database providers (e.g. postgis, sqlserver 2008, ...) and change the sql query strings in it to match mysql syntax. Once you have that done, it'd be great if you post a patch ;-).

Hth FObermaier

Apr 7, 2010 at 4:37 PM
Edited Apr 7, 2010 at 4:38 PM

thanks a lot i have find exactly what i needed,but i did'nt implement a mysql  provider for now but may be i'll do one in a few week

double[] utmCoordinate = new double[2];
SharpMap.Data.FeatureDataSet fdsBatiment = new FeatureDataSet();   

DataSet dsBatiment = mySqlCartoData.GetPositionBatiment("batiment");

FeatureDataTable fdt = new FeatureDataTable(dsBatiment.Tables[0]);
foreach (DataColumn col in dsBatiment.Tables[0].Columns)
{
              
fdt.Columns.Add(col.ColumnName, col.DataType, col.Expression);
}

foreach (DataRow drPoint in dsBatiment.Tables[0].Rows)
{
  string X = drPoint["X"].ToString().Replace(".", ",");
  string Y = drPoint["Y"].ToString().Replace(".", ",");

  if (!string.IsNullOrEmpty(X) && !string.IsNullOrEmpty(X))
  {
     mtmCoordinate[0] = double.Parse(X);
     mtmCoordinate[1] = double.Parse(Y);
  }

  if (utmCoordinate[0] != mtmCoordinate[1] && utmCoordinate[0] != 0)
  {
    //Convert mtm Coordinate log lat
    double[] lonlatCoordinate = MercatorToWgs84LatLon(utmCoordinate);
    drPoint["X"] = lonlatCoordinate[0];
    drPoint["Y"] = lonlatCoordinate[1];

    SharpMap.Geometries.Point point = new SharpMap.Geometries.Point(lonlatCoordinate[0], lonlatCoordinate[1]);

    FeatureDataRow fdr = fdt.NewRow();
    foreach (DataColumn col in dsBatiment.Tables[0].Columns)
    {                      
    fdr[col.ColumnName] = drPoint[col];
    }
                
    fdr.Geometry = point;
    fdt.AddRow(fdr);
  }
}
fdsBatiment.Tables.Add(fdt);