from GeoJSON data to FeatureLayer

5722
4
08-28-2012 03:12 AM
JulienRichard
New Contributor
Hello 😄

I'm currently working on an offline app.

I have an internal database (Spatialite) that allows me to generate simple GeoJSON files via an SQL query, which only specifies the geometry type and the coordinates of the object.

I'm trying currently to generate a FeatureLayer from theses JSON objects. If I understand correctly, using the FeatureCollection sample and the BladeRunner source code, I would need to define a JSON output format, have a correctly formated JSON file containing my values, parse this file using the JSON definition, put the results in a Graphics object, then these in a FeatureSet, and construct my feature layer with the FeatureSet and the json definition.

Is there another way to do this? Do you have something more comprehensible? because BladeRunner's workflow to decode JSOn is quite difficult to understand, while FeatureCollection doesn't really fit with my needs since it uses an online resource.

Thanks in advance 🙂
0 Kudos
4 Replies
JulienRichard
New Contributor
Ok nevermind I managed to get this working.
I'll post what I did to make this work when I finish my work 😉

UPDATE

Ok so here's how i do it :

1. Parsing JSON string to get attributes and geometry, store them in an object.
2. Reproject if necessary to Web Mercator (102100) and create a Graphic object for
each item in the json file. Add it to a List of Graphics.
2. Write layer definition, with GeometryType, objectIdField, renderer and fields.
3. Create a FeatureSet, then setGraphics on it with the graphics created earlier
4. Instanciate an ArcGISFeatureLayer with the layer definition, the feature set, and options mode.
5. Simply add layer to map.

Ok, done. (I'll add details in some sort of tutorial if needed)

The problem now is GC (Garbage Collector).
I have a query where there are 3000 objects returned, geometry type : point.
To do all the things above, and also including the sql query, it takes around 1 second, which I would say is not bad considering the sql query, the json parsing, the generation of 3000 Graphics etc.

But next step is to actually showing the layer on the map. The layer does show up, and correctly, but after 15 to 20 seconds!
8-30 13:53:20.555: D/dalvikvm(26747): GC_CONCURRENT freed 2261K, 39% free 8878K/14407K, paused 2ms+3ms
08-30 13:53:20.766: D/dalvikvm(26747): GC_CONCURRENT freed 637K, 38% free 8981K/14407K, paused 2ms+3ms
08-30 13:53:20.993: D/dalvikvm(26747): GC_CONCURRENT freed 672K, 37% free 9083K/14407K, paused 2ms+4ms
.
.
.
08-30 13:53:37.485: D/dalvikvm(26747): GC_CONCURRENT freed 709K, 39% free 8809K/14407K, paused 2ms+3ms
08-30 13:53:37.633: D/dalvikvm(26747): GC_CONCURRENT freed 715K, 39% free 8810K/14407K, paused 2ms+3ms
08-30 13:53:37.782: D/dalvikvm(26747): GC_CONCURRENT freed 717K, 39% free 8809K/14407K, paused 2ms+4ms
08-30 13:53:40.407: D/dalvikvm(26747): GC_CONCURRENT freed 2073K, 50% free 7332K/14407K, paused 5ms+3ms


This takes 20 seconds and there are around 100 GC_CONCURRENT occurrences.
All of this happen just after adding the layer to the map.

I have no idea why. I understand that there are thousands of objects in memory, but I don't know what exactly the GC is collecting. I  used MAT on Eclipse but nothing particular showed up.
Plus I don't understand why the GC doesn't free memory after showing the layer on the map.

So if you have any idea about this, feel free to reply 🙂
0 Kudos
VivekRane
New Contributor
Ok nevermind I managed to get this working.
I'll post what I did to make this work when I finish my work 😉

UPDATE

Ok so here's how i do it :

1. Parsing JSON string to get attributes and geometry, store them in an object.
2. Reproject if necessary to Web Mercator (102100) and create a Graphic object for
each item in the json file. Add it to a List of Graphics.
2. Write layer definition, with GeometryType, objectIdField, renderer and fields.
3. Create a FeatureSet, then setGraphics on it with the graphics created earlier
4. Instanciate an ArcGISFeatureLayer with the layer definition, the feature set, and options mode.
5. Simply add layer to map.

Ok, done. (I'll add details in some sort of tutorial if needed)

The problem now is GC (Garbage Collector).
I have a query where there are 3000 objects returned, geometry type : point.
To do all the things above, and also including the sql query, it takes around 1 second, which I would say is not bad considering the sql query, the json parsing, the generation of 3000 Graphics etc.

But next step is to actually showing the layer on the map. The layer does show up, and correctly, but after 15 to 20 seconds!
8-30 13:53:20.555: D/dalvikvm(26747): GC_CONCURRENT freed 2261K, 39% free 8878K/14407K, paused 2ms+3ms
08-30 13:53:20.766: D/dalvikvm(26747): GC_CONCURRENT freed 637K, 38% free 8981K/14407K, paused 2ms+3ms
08-30 13:53:20.993: D/dalvikvm(26747): GC_CONCURRENT freed 672K, 37% free 9083K/14407K, paused 2ms+4ms
.
.
.
08-30 13:53:37.485: D/dalvikvm(26747): GC_CONCURRENT freed 709K, 39% free 8809K/14407K, paused 2ms+3ms
08-30 13:53:37.633: D/dalvikvm(26747): GC_CONCURRENT freed 715K, 39% free 8810K/14407K, paused 2ms+3ms
08-30 13:53:37.782: D/dalvikvm(26747): GC_CONCURRENT freed 717K, 39% free 8809K/14407K, paused 2ms+4ms
08-30 13:53:40.407: D/dalvikvm(26747): GC_CONCURRENT freed 2073K, 50% free 7332K/14407K, paused 5ms+3ms


This takes 20 seconds and there are around 100 GC_CONCURRENT occurrences.
All of this happen just after adding the layer to the map.

I have no idea why. I understand that there are thousands of objects in memory, but I don't know what exactly the GC is collecting. I  used MAT on Eclipse but nothing particular showed up.
Plus I don't understand why the GC doesn't free memory after showing the layer on the map.

So if you have any idea about this, feel free to reply 🙂


Can u please add a tutorial, how to do that?
0 Kudos
DanO_Neill
Occasional Contributor III
Take a look at the CreateLocalJsonFeatures sample from ArcGIS Online.  It is more focused on the json to features workflow.  Look at the LocalMapActivity.createWindTurbinesFeatureSet() method. 

  
  // path is location of json file  
  public FeatureSet createWindTurbinesFeatureSet(String path) {
    FeatureSet fs = null;
    
    try {
      JsonFactory factory = new JsonFactory();
      JsonParser parser = factory.createJsonParser(new FileInputStream(path));
      parser.nextToken();
      fs = FeatureSet.fromJson(parser);

    } catch (Exception e) {
      e.printStackTrace();
    }
    
    return fs;
  } 
0 Kudos
MH9
by
New Contributor

This answer has been useful to a solution of mine that I am working on.  Can anyone suggest here as to how to enable Identify on this layer. Can i give path of offline json file for the identify task service or is there some other approach. Kindly advise.

Thanks in advance.

0 Kudos