Where are you supposed to plug in the featurefromdescription block?

We really need a whole lot of examples on how to use Maps with FeatureCollections and in particular featurefromdescription
Please?

And what exactly do you plug INTO featurefromdescription ?
text list like?

This is by no means clear:-
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
FeatureFromDescription( description )

Converts a feature description into an App Inventor map feature. Points are converted into Marker components, LineStrings are converted into LineString components, and Polygons (and MultiPolygons) are converted into Polygon components. If the feature has properties, they will be mapped into App Inventor properties using the following mapping:

  • description becomes Description
  • draggable becomes Draggable
  • infobox becomes EnableInfobox
  • fill becomes FillColor
  • fill-opacity becomes FillOpacity
  • image becomes ImageAsset
  • stroke becomes StrokeColor
  • stroke-opacity becomes StrokeOpacity
  • stroke-width becomes StrokeWidth
  • title becomes Title
  • visible becomes Visible
    ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

I dont even know where you plug the CreateMarker block?

Hello Al..

What are you trying to do Al? Knowing that, someone could provide specific advice.

MIT really does not provide a hand fed tutorial. For examples for your question you might start here. Read the examples; there are a few tutorials w.r.t. Markers. Also search the community forum for Maps, geojson, json, linestring, polygons etc. where you should find discussions about how to use specific Map components.

The National Parks tutorial) demonstrates how to plot multiple run time markers using a csv file to an OpenStreetMap. Use the list from csv Block to convert the csv to a List. What you do depends on how you make your List, where it is stored or is downloaded from.

Using Polygons Extract Json (Polygon.PointsFromString) Data in a txt file - #5 by SteveJG

FeatureCollection references in old Forum

There are examples in the haystack of topics shown above. Here is a way to create run time Markers from a List (converted csv)

. There are simpler ways to use the Block but one has to know where the information for the CreateMarker Block originates and how you intend to use the runtime marker. Often, it is simpler to just use one or two design time Markers.

Regards,
Steve

Hi @Al_Scotch,

Thanks for your questions.

FeatureFromDescription is intended to be used from within the context of GotFeatures event. The second parameter to that event, features is a list of feature descriptions parsed from GeoJSON. You can iterate over each element in this list to (optionally) manipulate or filter it before passing it to FeatureFromDescription. The elements of features are associative lists containing the key-value pairs from the GeoJSON for the given feature. (Maps predates the addition of dictionaries to the App Inventor language, otherwise they would have been dictionaries).

Note: If you don't provide an implementation for GotFeatures (i.e., you don't include the event block in your project), then the system will provide a default implementation that will pass each feature description directly to the method add the resulting component to the Map or FeatureCollection.

For CreateMarker, it creates a instance of Marker, adds it to the Map, and returns the marker, which you can pass to the "Any Marker" blocks, if further customization of the marker is desired. If you don't need to customize the marker, you can connect this block to the input of the evaluate but ignore result block.

why not working ?

There are a few issues with your example:

  1. FeatureFromDescription expects a single feature. You're handing it a list with a string "features" and then a feature description. You need to only hand it the latter.
  2. The type should be "Feature", not "feature"
  3. Lastly, for Polygon features the coordinates must be a list of linear ring coordinates arrays per the GeoJSON spec, so your coordinates need an extra make a list level to satisfy that constraint.

For example:

Hmmm

You made the same mistake. Point #3 is that you have to add an extra layer of make a list. My blocks image should be draggable into App Inventor for testing.

So I did :upside_down_face:

I also note that the coordinates should be in the order: lon/lat

Circles ?

I understand these are not a part of geoJson....

(draggable block)

Of interest, the geoJson returned by the map for a Circle does not contain a radius...

{"type":"Feature","geometry":{"type":"Point","coordinates":[-71.09098434448244,42.363617631805496]},"properties":{"$Type":"com.google.appinventor.components.runtime.Circle","draggable":false,"infobox":false,"visible":true,"stroke":"&Hff000000","stroke-opacity":1,"stroke-width":1,"fill":"&Hffff0000","fill-opacity":1}}

Perhaps explained here in part about what can be 'translated' by App Inventor

Yes, it does not handle Circle radius as the mapping does not exist. :astonished:

Possible bug or issue ?

Using design time Polygon

image

Using featurefromdescription blocks

image

Tested with other regular polygons much the same happens

Are you sure that your blocks are correct? I believe GeoJSON uses the easting coordinate first then the northing coordinate. It was a bit of an API design failure on my part when I made the Points property use latitude (northing) first. You should also make sure that the winding order is correct so that points are visited clockwise around the polygon. Usually these types of artifacts are caused by not having the correct winding order.

I attempted switching lat and lon around but that built the polygon somewhere in the sea, a different shape but with the same issue.

Hopefully you can see that the lat/lon pairs are in the same "winding" order for the design time polygon (which makes a hexagon) as for the featurefromdescription polygon (which doesn't make a hexagon)

Not sure what else to try ?

Had a play around, and it seems you were on the right lines with the order of eastings/northings.

I set some coordinates (in clockwise order) to draw a 4 sided polygon. Lo and behold, I got the criss-cross layout. Then I ordered the coordinates by latitude/northings (descending order) and, hey presto, the polygon drew as expected!

More testing to do...

The above only worked with a four sided polygon :frowning:

However, found the solution. :slight_smile:

Don't worry about setting the coordinates you want when running FeatureFromDescription just set any coordinates you want (I used 0,0 three times), in order to generate the polygon component. Then use the anyComponent blocks for the Polygon (so you will need a silent designer polygon in place), to set the coordinates you do want.

image

Now, it seems, we have a method for creating runtime polygons, lineStrings, rectangles, and circles (as polygons...)

:slight_smile:

1 Like

That is an inspired approach Tim, easier to understand and pretty much bullet proof. :trophy:

1 Like

Just attempted to make a LineString using FeatureFromDescription - failed

Is something different required?

Had a look at Rectangle, but the geoJson for that looks quite different. I guess just use polygon for that?