Graphic with spatial Reference?

4266
2
03-20-2015 01:43 PM
ForrestKaye
New Contributor III

I cannot seem to get a graphic with a spatial reference.

I have a basemap as a tpk.  My mapview and Graphics layer have a spatial reference.  I have tried many methods two are listed below that I thought should work.

public boolean onSingleTap(final MotionEvent e) {
     Geometry geometry = mMapView.toMapPoint(new Point(e.getX(), e.getY()));
     Graphic graphic = new Graphic(geometry, pointSymbol);
     SpatialReference spatialReference = graphic.getSpatialReference();//=null
}

I've also tried to project it.

public boolean onSingleTap(final MotionEvent e) {     
     Geometry geometry = mMapView.toMapPoint(new Point(e.getX(), e.getY()));
     Geometry RealProj = GeometryEngine.project(geometry, mMapView.getSpatialReference(), mMapView.getSpatialReference());
     Graphic graphic = new Graphic(geometry, pointSymbol);
     SpatialReference spatialReference = graphic.getSpatialReference();//=null
}

Nothing seems to work.  Is there something obvious I am not doing?  This has not been an issue until I have started trying to use the FeatureSet.toJson method and realized that my spatial reference was empty.

Thanks in advance for any help.

0 Kudos
2 Replies
omega_cancer
Occasional Contributor II

Have you tried to get spatial ref of graphic after adding it to layer.

I think graphic gets its spatial Ref assigned after it is added to layer

0 Kudos
ForrestKaye
New Contributor III

I have tried that.  My code supplied above is very simplified.  I had a graphic added to a graphics layer then I pass that graphic to another intent by graphicLayer.getGraphic(UID).  I have yet to be successful in this.

I have however solved the ultimate issue of setting the spatial Reference of my FeatureSet which can be accomplished by simply using the "setSpatialReference(SR)" method.  But the graphic and Spatial Reference issue is still a mystery to me.

0 Kudos