ThinkGeo.com    |     Documentation    |     Premium Support

How to get geometry type for feature layer?

Hi.


I'm looking for a method to get geomatry type for feture layer (polygon, point, line). Is there any? Or I have to do this with a query on feature data source?


 


Thanks in advance



Hello 
  
 ShapeFileFeatureLayer.GetShapeFileType() is what you’re looking for. 
  
 Here is my code: 
  
      l.Open(); 
       if (l.GetShapeFileType()== ShapeFileType.Point || 
          l.GetShapeFileType() == ShapeFileType.PointM || 
          l.GetShapeFileType() == ShapeFileType.PointZ || 
          l.GetShapeFileType() == ShapeFileType.Multipoint || 
          l.GetShapeFileType() == ShapeFileType.MultipointM || 
          l.GetShapeFileType() == ShapeFileType.MultipointZ) 
         ret= GsiShapeType.Point; 
  
       else if (l.GetShapeFileType() == ShapeFileType.Polyline || 
        l.GetShapeFileType() == ShapeFileType.PolylineM || 
        l.GetShapeFileType() == ShapeFileType.PolylineZ) 
         ret= GsiShapeType.Ligne; 
  
       else  
         ret= GsiShapeType.Surface; 
  
       l.Close(); 
 


Thanks, but I need this for PostgreSqlFeatureLayer.


I thougth that it may be done with some FeatureLayer property, but no.


Regards


 



Patrick, thanks for the sharing!


Łukasz,


PostgreSqlFeatureLayer is different from ShapeFileFeatureLayer in some way. Normally the records in a shape file have the same type, and we can use GetShapeType method to get it.

But the records in a Postgre table do not need to share the same type. One thing you can do is to get the type of the first Feature and use that as the type of the table, if you know all the records are with the same type. Here’s the code:




DataTable dt = postgreSqlFeatureLayer.QueryTools.ExecuteQuery("select AsBinary(GeometryColumnName) from TableName limit 1;");
WellKnownType wellKnownType = WellKnownType.Invalid;
if (dt.Rows.Count > 0)
{
    Feature feature = new Feature((byte[])dt.Rows[0][0]);
    wellKnownType = feature.GetWellKnownType();
}


We have created a tracking system issue to add method GetFirstGeometryType in Postgre, Oracle and SQL layer, we will implement it later.


Thanks,

ThinkGeo Support