Select to view content in your preferred language

getGeometryType() not working?

583
1
Jump to solution
05-16-2012 10:07 AM
KevinNetherton
New Contributor II
Hey all

I have a bunch of ArcGISFeatureLayer objects which originate from a map package.  I'd like to be able to query the geometry type and set different opacity levels depending on the geometry type.  Below is a very simple example of the type of thing I am trying to do.  Unfortunately it seems that the method getGeometryType() always returns a null value.  Yes I've tried with different map packages and different layers, but it seems like the getGeometryType() always comes back as null.

Is there another way to find out what kind of geometry the feature class that sits behind the ArcGISLocalFeatureLayer object has.

package testing;  import com.esri.client.local.ArcGISLocalFeatureLayer; import com.esri.core.geometry.Geometry.Type;  public class getGeomTypes {    public static void main(String[] args) {   String mapPackage = "C:\\eclipse_config\\3.7.2\\ITN_EditMap\\data\\set1\\mapPackge_referencesdata_includesSDE.mpk";   ArcGISLocalFeatureLayer flObj = new ArcGISLocalFeatureLayer( mapPackage, "roads_gdbc");   Type geomType = flObj.getGeometryType();   if (geomType == Type.Polygon || geomType == Type.Envelope) {    flObj.setOpacity(3f);   } else {    flObj.setOpacity(8f);   }  }  }



Cheers

Kevin
0 Kudos
1 Solution

Accepted Solutions
Jan-Tschada
Esri Contributor
As far as I can judge it, you need to initialize (starts the local server and so on) the layer first. Otherwise the layer instance is useless. See code snippet below.

 @Test  public void addLocalFeatureLayer() throws InterruptedException {   final Lock lock = new ReentrantLock();   lock.lock();   try {    final Condition condition = lock.newCondition();    final ArcGISLocalFeatureLayer layer = new ArcGISLocalFeatureLayer(mapPackagePath, "Germany");    layer.addLayerInitializeCompleteListener(new LayerInitializeCompleteListener() {          @Override     public void layerInitializeComplete(LayerInitializeCompleteEvent e) {           lock.lock();      try {       assertTrue("The local layer must have a valid URL!", null != layer.getUrl());       Type geometryType = layer.getGeometryType();       assertTrue("The geometry type is not valid!", Geometry.Type.Polygon == geometryType);      } finally {       condition.signal();       lock.unlock();      }     }    });    layer.initializeAsync();        condition.await();   } finally {    lock.unlock();   }  }
Product Manager
Developers and Location Services
Germany and Switzerland

View solution in original post

0 Kudos
1 Reply
Jan-Tschada
Esri Contributor
As far as I can judge it, you need to initialize (starts the local server and so on) the layer first. Otherwise the layer instance is useless. See code snippet below.

 @Test  public void addLocalFeatureLayer() throws InterruptedException {   final Lock lock = new ReentrantLock();   lock.lock();   try {    final Condition condition = lock.newCondition();    final ArcGISLocalFeatureLayer layer = new ArcGISLocalFeatureLayer(mapPackagePath, "Germany");    layer.addLayerInitializeCompleteListener(new LayerInitializeCompleteListener() {          @Override     public void layerInitializeComplete(LayerInitializeCompleteEvent e) {           lock.lock();      try {       assertTrue("The local layer must have a valid URL!", null != layer.getUrl());       Type geometryType = layer.getGeometryType();       assertTrue("The geometry type is not valid!", Geometry.Type.Polygon == geometryType);      } finally {       condition.signal();       lock.unlock();      }     }    });    layer.initializeAsync();        condition.await();   } finally {    lock.unlock();   }  }
Product Manager
Developers and Location Services
Germany and Switzerland
0 Kudos