converting Json coordinate into CLLocationCoordinate2D - objective-c

I have a service returning geographies (points and polygons) the object return as strings for example:
"POINT (51.38494009999999 -0.3514684)"
I can do string manipulations to extract the two values but was wondering if there is a better way to convert that into CLLocationCoordinate2D.
mainly because of the polygons, inserting point by point doesn't seem like the correct solution.

If you want a more appropriate structure to represent a polygon, you could use the MKPolygon class from MapKit. It accepts an array of CLLocationCoordinate2D points as it's initialiser. Using this class may be handy if you are planning to interact with MapKit in your application. Otherwise, it is probably unnecessary to do so - a custom class will likely be the desired container then.

You are seeing well-known text, which was produced by ST_AsText. If you actually were expecting JSON and you are able to modify the server-side query, use ST_AsGeoJSON to instead return:
{"type":"Point","coordinates":[51.3849401,-0.3514684]}
If you have only point data, also consider returning the double precision data, ST_X for longitude and ST_Y for latitude. The last suggestion of course does not require any parsing of text results, but does not work on linestrings or polygons.

Related

PostGIS and coordinates, determinate if a point is inside a polygon/multipolygon (kml)

My goal is to determinate if a point (coordinate) in Input is inside the polygon (both the point and polygon/multipolygon are geographic objects from postGIS). Now my query always return false.
Basically this always returns false even if the point is inside the polygon:
select st_contains(st_geomfromtext('POINT(42.17591110412206 13.716918686169493)',4326),st_geomfromkml('<Polygon><outerBoundaryIs><LinearRing><coordinates>13.722101,42.177614,0 13.72....... </Polygon>')
);
i truncated the kml of course, anyway the format is (lat,lng,0), also on the point i used 4326 and i'm not sure if the value is correct. Also i tried both
Point(LAT,LNG) and Point(LNG,LAT)
Could anyone help me? I'm really out of ideas, surely there is something wrong on my query.
Actually, regarding to official documentation (https://postgis.net/docs/ST_Contains.html):
boolean ST_Contains(geometry geomA, geometry geomB);
Returns TRUE if geometry B is completely inside geometry A.
A point cannot contain polygon ;)

wxWidgets - wxGrid - reading/writing non string cell values

I have a wxGrid to edit an array of numerical data.
I was wondering what's the best way to get non-string data in and out of the cells without going through the string to numeric conversion all the time.
I've used SetCellEditor() to control the data entry.
currently I use this:
// numeric value into cell
str.clear();
str << val1;
m_grid4->SetCellValue(row, col, str);
..
// read value from back into variable
val = atoi(m_grid4->GetCellValue(row, col));
Apart from the fact that atoi() is a bit ugly and a template function with a stringstream would be better, is there a way do get non-string values a bit better in and out of cells?
I was looking at the editors and renderers but can't figure it out.
If you worry about efficiency, you almost certainly should use a custom table class deriving from wxGridTableBase instead of using the default trivial wxGridStringTable implementation which stores everything as strings. Then, and much less importantly, if it makes sense in your case, you can use wxGridCellNumberRenderer which will call your table GetValueAsLong() method instead of GetValue() (which returns a string).
Both of those are demonstrated in wxGrid sample, notably look at BugsGridTable there.
Good luck!

wxStaticText inconsistently displays 'degree' character

In the same application I have two different instances of wxStaticText. Each displays an angular value expressed in degrees. I've tested both instances for font name and font encoding. They are the same for both. I've tested that both strings passed to SetLabel() are using the same character value, decimal 176. Yet one displays the 'degree' character (small circle, up high) as expected and the other instead displays an odd character I'm not familiar with. How can this be? Is there some other property of wxStaticText I need to test?
I can't explain what you're seeing because obviously two identical controls must behave in the same way, but I can tell you that using decimal 176 is not a good way to encode the degree sign, unless you explicitly use wxConvISO8859_1 to create the corresponding wxString.
It is better to use wxString::FromUTF8("\xc2\xb0") instead or, preferably, make sure that your source files are UTF-8 encoded and just use wxString::FromUTF8("°").
Arghhhh! Found it. I was assuming SetLabel() was wxStaticText::SetLabel(), inherited from the wxWindow base class. It's not. We have a wrapper class of our own around wxStaticText that I was not aware of. It's the wrapper class that is bollixing the string value.
Moral: When debugging unfamiliar code, don't make assumptions, step ALL THE WAY in.

String Template: is it possible to get the n-th element of a Java List in the template?

In String Template one can easily get an element of a Java Map within the template.
Is it possible to get the n-th element of an array in a similar way?
According to the String Template Cheat Sheet you can easily get the first or second element:
You can combine operations to say things like first(rest(names)) to get second element.
but it doesn't seem possible to get the n-th element easily. I usually transform my list into a map with list indexes as keys and do something like
map.("25")
Is there some easier/more straightforward way?
Sorry, there is no mechanism to get a[i].
There is no easy way getting n-th element of the list.
In my opinion this indicates that your view and business logic are not separated enough: knowledge of what magic number 25 means is spread in both tiers.
One possible solution might be converting list of values to object which provides meaning to the elements. For example, lets say list of String represents address lines, in which case instead of map.("3") you would write address.street.

Semantic mediawiki - Set propery to range of values

I'm trying to set a specific property to a non exact value, for example say that I want to define the height of a pine tree to usually between 3-80 m (according to wikipedia). Then I would like to set something like [[Has height::3-80]] (of course this doesn't work) and defining the unit to meters with "custom units". Then I would like to be able to query for example "trees that can reach the height of 70 meters" and the pine tree would be included. I've been searching and trying different angles for hours now and I can't figure it out. Tried with #set_recurring_event but that seems to be only for dates/time. Also understood how to set multiple values for a property with #arraymap but this doesn't seem to help me here. Really would appreciate help with this (it's probably very easy and right in front of me) Thx! COG
There's no such things. But you able to create template, with parameters you want. The you just use code kinda {{range|min|max|units}}. For example your range of heights looks like {{range|3|80|m}}.