Below I have what I'd expect is a way to create a GeoJSON MultiPolygon object with one polygon in it which has two "holes".
When I use the service http://geojson.io/ to validate this object, it returns with an error each element in a position must be a number and it does not render, however if I remove the "holes" nest, removing one of them then it works.
I'm looking for a way to describe a MultiPolygon where the polygons can have multiple holes.
I'm not looking for a way in code to create a polygon with holes.
I'm looking for a way to use the GeoJSON spec to represent MultiPolygons with multiple holes.
{
"type": "MultiPolygon",
"coordinates": [
[
[
[
-73.98114904754641,
40.7470284264813
],
[
-73.98314135177611,
40.73416844413217
],
[
-74.00538969848634,
40.734314779027144
],
[
-74.00479214294432,
40.75027851544338
],
[
-73.98114904754641,
40.7470284264813
]
],
[
[
[
-73.99818643920906,
40.74550031602355
],
[
-74.00298643920905,
40.74550031602355
],
[
-74.00058643920897,
40.74810024102966
],
[
-73.99818643920906,
40.74550031602355
]
],
[
[
-73.98917421691903,
40.73646098717515
],
[
-73.99397421691901,
40.73646098717515
],
[
-73.99157421691893,
40.739061265535696
],
[
-73.98917421691903,
40.73646098717515
]
]
]
]
]
}
This is how it works:
{
"type": "MultiPolygon",
"coordinates": [
[
{polygon},
{hole},
{hole},
{hole}
]
]
}
Not like this:
{
"type": "MultiPolygon",
"coordinates": [
[
{polygon},
[
{hole},
{hole},
{hole}
]
]
]
}
Here's an example!
{
"type": "MultiPolygon",
"coordinates": [
[
[
[
-47.900390625,
-14.944784875088372
],
[
-51.591796875,
-19.91138351415555
],
[
-41.11083984375,
-21.309846141087192
],
[
-43.39599609375,
-15.390135715305204
],
[
-47.900390625,
-14.944784875088372
]
],
[
[
-46.6259765625,
-17.14079039331664
],
[
-47.548828125,
-16.804541076383455
],
[
-46.23046874999999,
-16.699340234594537
],
[
-45.3515625,
-19.31114335506464
],
[
-46.6259765625,
-17.14079039331664
]
],
[
[
-44.40673828125,
-18.375379094031825
],
[
-44.4287109375,
-20.097206227083888
],
[
-42.9345703125,
-18.979025953255267
],
[
-43.52783203125,
-17.602139123350838
],
[
-44.40673828125,
-18.375379094031825
]
]
]
]
}
For your example in fact it's not really a MultiPolygon (in the sense of geoJSON) but a simple Polygon (with a single outer ring and multiple inner rings for the holes).
Note the difference with Multipolygons in OSM (which represents them as a relation containing ways, and whose first and last node should be merged to the same "node" element (something that does not exist in geoJSON where they are unified only by the fact that the two nodes have the same coordinates, but will in reality be automatically closed by an additional segment for "Polygon" and "MultiPolygon" types of GeoJSON)
Note that when you import a geoJSON in OSM editors (such as JOSM) they will be imported with separate nodes for the first and last node, even if they have the same coordinates - you need to use the JOSM validator to detect superposed nodes and merge them after the import in JOSM but before submission to OSM.
But in scripts or general use of geoJSON, all rings (arrays of coordinate pairs) in a "type":"Polygon" or members of a "type":"Polygon" are not required to include the same coordinates for the last node as the first node, because it is implicit (but it is still recommended to add this duplicate node for compatibility). Such closure of rings is implicit for "Polygon" and "MultiPolygon" (as they represent surfaces), but not for "Polyline" and "MultiPolyline" (as they represent curves) where you still need to include twice the same coordinates for the first and last node to get closed curves.
To represent an OSM "multipolygon" with multiple "outer" rings, you have to include several "[ {outer},{inner*} ]" in the main array of coordinates for the geoJSON "MultiPolygon" type, i.e.
{"type":"MultiPolygon", "coordinates":[
[
[[x0,y0], [x1,y1], ... [x0,y0]], /*outer1*/
[[x0,y0], [x1,y1], ... [x0,y0]], /*inner1, optional*/
[[x0,y0], [x1,y1], ... [x0,y0]], /*inner2, optional*/
],[
[[x0,y0], [x1,y1], ... [x0,y0]], /*outer2*/
],...,[
[[x0,y0], [x1,y1], ... [x0,y0]], /*outer3*/
],[
[[x0,y0], [x1,y1], ... [x0,y0]], /*outer4*/
]
]}
So for your example, the solution is:
{"type":"Polygon", "coordinates":[
[[x0,y0], [x1,y1], [x2,y2], [x3,y3], [x0,y0]], /*outer1*/
[[x4,y4], [x5,y5], [x6,y6], [x4,y4]], /*inner1*/
[[x7,y7], [x8,y8], [x9,y9], [x7,y7]] /*inner2*/
]}
If you had several outer rings only (possibly overlapping to create an union of surfaces, but this is not recommended) it would need to be a MultiPolygon, and here you would get no "holes":
{"type":"MultiPolygon", "coordinates":[
[[[x0,y0], [x1,y1], [x2,y2], [x3,y3], [x0,y0]]], /*outer1*/
[[[x4,y4], [x5,y5], [x6,y6], [x4,y4]]], /*outer2*/
[[[x7,y7], [x8,y8], [x9,y9], [x7,y7]]] /*outer3*/
]}
Note there's one less level of [square braces] because we can use "Polygon" here instead of a Multipolygon that would contain only one member in your example.
As far as I know, you can use SUBSTR(JSON_EXTRACT(ST_ASGEOJSON(WKT) function if converting from wkt to geography. That way you can represent in map. What I found in bigquery is seems like multipolygon with holes switch position for holes coordinates when u use ST_ASGEOJSON().
And check out this link:
https://dev.socrata.com/docs/datatypes/multipolygon.html#,
Related
the following is the JSON data. need to get only of id key
{apps:[ {
"id": "/application1/4b693882-ffba-4c93-a0f2-cccafcb4d7dd",
"cmd": null,
"args": null,
"user": null,
"env": {},
"constraints": [
[
"hostname",
"GROUP_BY",
"5"
]
},
{
"id": "/application2/4b693882-ffba-4c93-a0f2-cccafcb4d7dd",
"cmd": null,
"args": null,
"user": null,
"env": {},
"constraints": [
[
"hostname",
"GROUP_BY",
"5"
]
]},
output expected is
/application1/4b693882-ffba-4c93-a0f2-cccafcb4d7dd
/application2/4b693882-ffba-4c93-a0f2-cccafcb4d7dd
Thanks in advance
After fixing the errors in your JSON, we can use the following jq filter to get the desired output:
.apps[] | .id
JqPlay Demo
Result jq -r '.apps[] | .id':
/application1/4b693882-ffba-4c93-a0f2-cccafcb4d7dd
/application2/4b693882-ffba-4c93-a0f2-cccafcb4d7dd
You can use map() to create an array from the properties of the objects. Try this:
let data = {apps:[{"id":"/application1/4b693882-ffba-4c93-a0f2-cccafcb4d7dd","cmd":null,"args":null,"user":null,"env":{},"constraints":["hostname","GROUP_BY","5"]},{"id":"/application2/4b693882-ffba-4c93-a0f2-cccafcb4d7dd","cmd":null,"args":null,"user":null,"env":{},"constraints":["hostname","GROUP_BY","5"]}]}
let ids = data.apps.map(o => o.id);
console.log(ids);
Note that I corrected the invalid brace/bracket combinations in the data structure you posted in the question. I assume this is just a typo in that example, otherwise there would be parsing errors in the console.
The documentations says that Cosmos supports Multipolygons but when I want to query using it I don't get the expected result.
If I change the multipolygon to a polygon the query works as expected.
This is the result of ST_ISVALIDDETAILED with the multipolygon
Invalid position. A position must be represented by an array of
numbers. There must be at least two elements in the array.
This is proof that the multipolygon is not working.
Has anyone been able to work with multipolygons?
Note:
I have used the multipolygon as example in the documentation.
I have created the spatial index for the property.
{
"path": "/Region/Area/?",
"types": [
"Point",
"LineString",
"Polygon",
"MultiPolygon"
]
}
After investigating more I found that the example on documentation is bad formed.
This is the example =>
{
"type":"MultiPolygon",
"coordinates":[ [
[52.0, 12.0],
[53.0, 12.0],
[53.0, 13.0],
[52.0, 13.0],
[52.0, 12.0]
],
[
[50.0, 0.0],
[51.0, 0.0],
[51.0, 5.0],
[50.0, 5.0],
[50.0, 0.0]
] ]
}
and is invalid.
This is the right geoJson =>
{
"type":"MultiPolygon",
"coordinates":[ [[
[52.0, 12.0],
[53.0, 12.0],
[53.0, 13.0],
[52.0, 13.0],
[52.0, 12.0]
]],
[[
[50.0, 0.0],
[51.0, 0.0],
[51.0, 5.0],
[50.0, 5.0],
[50.0, 0.0]
]]]
}
I want to create a custom keybinding in sublime text 3 that doesn't return a command but returns the key combination used in R to define a variable like below.
variable <- variable_definition //for example
z1 <- seq(1,100)
In R 3.2.2 GUI mac OS X the keybinding:
"alt+-" returns " <- "
I have read the documentation for user keybindings but couldn't find something that I could use.
I have tried "print" and "echo" as below but they don't work.
[
{ "keys": ["alt+-"], "print": " <- "}
]
or
[
{ "keys": ["alt+-"], "echo": " <- "}
]
Some help would be much appreciated
In Sublime Text you run commands with arguments. If you want to insert something the command is insert and the argument is called characters. If you want to limit it to the language R you can add a context. Hence the keybinding:
[
{
"keys": ["alt+-"], "command": "insert", "args": {"characters": " <- "},
"context":
[
{ "key": "selector", "operator": "equal", "operand": "source.r" }
]
}
]
Aside: it could also be interesting for you to use snippets as keybindings.
[
{
"keys": ["alt+-"], "command": "insert_snippet", "args": {"contents": "${1:variable} <- ${0:definition}"}
}
]
Given a working makefile which crop a world map to a specific country's bounding box.
# boxing:
INDIA_crop.tif: ETOPO1_Ice_g_geotiff.tif
gdal_translate -projwin 67.0 37.5 99.0 05.0 ETOPO1_Ice_g_geotiff.tif INDIA_crop.tif
# ulx uly lrx lry // W N E S
# unzip:
ETOPO1_Ice_g_geotiff.tif: ETOPO1.zip
unzip ETOPO1.zip
touch ETOPO1_Ice_g_geotiff.tif
# download:
ETOPO1.zip:
curl -o ETOPO1.zip 'http://www.ngdc.noaa.gov/mgg/global/relief/ETOPO1/data/ice_surface/grid_registered/georeferenced_tiff/ETOPO1_Ice_g_geotiff.zip'
clean:
rm `ls | grep -v 'zip' | grep -v 'Makefile'`
Given I currently have to change this makefile each time by hand editing the makefile to change:
1. the country name,
2. its North border geocoordinate,
3. its South border geocoordinate,
4. its East border geocoordinate,
5. its West border geocoordinate.
Given I also have a dataset for all countries such :
data = [
{ "W":-62.70; "S":-27.55;"E": -54.31; "N":-19.35; "item":"Paraguay" },
{ "W": 50.71; "S": 24.55;"E": 51.58; "N": 26.11; "item":"Qatar" },
{ "W": 20.22; "S": 43.69;"E": 29.61; "N": 48.22; "item":"Romania" },
{ "W": 19.64; "S": 41.15;"E":-169.92; "N": 81.25; "item":"Russia" },
{ "W": 29.00; "S": -2.93;"E": 30.80; "N": -1.14; "item":"Rwanda" },
{ "W": 34.62; "S": 16.33;"E": 55.64; "N": 32.15; "item":"Saudi Arabia"}
];
How to loop on each line of the data so to set parameters into my makefile ? So I output at once all the files COUNTRYNAME_crop.tif with the correct bounding boxes.
Assuming you're using GNU make, this seems to me like a perfect problem for autogenerated makefiles. After make reads in its makefiles it will test each one as if it were a target to see if it can be rebuilt. If so, and it is rebuilt, make will automatically re-exec itself. This is an extraordinarily powerful type of meta-programming. I would combine this with recursive variable naming.
1. Data: Let's assume your dataset is in dataset.out such :
[
{ "W":-62.70; "S":-27.55;"E": -54.31; "N":-19.35; "item":"Paraguay" },
{ "W": 50.71; "S": 24.55;"E": 51.58; "N": 26.11; "item":"Qatar" },
{ "W": 20.22; "S": 43.69;"E": 29.61; "N": 48.22; "item":"Romania" },
{ "W": 19.64; "S": 41.15;"E":-169.92; "N": 81.25; "item":"Russia" },
{ "W": 29.00; "S": -2.93;"E": 30.80; "N": -1.14; "item":"Rwanda" },
{ "W": 34.62; "S": 16.33;"E": 55.64; "N": 32.15; "item":"Saudi Arabia"}
];
2. Converter: Now you need to write the utility convert-to-makefile. I would write it in Perl myself but the new kids would probably choose Python. Whatever. Anyway, for each country, the output should be something like this:
COUNTRIES += <countryname>
<countryname>-NORTH := <north-coord>
<countryname>-SOUTH := <south-coord>
<countryname>-EAST := <east-coord>
<countryname>-WEST := <west-coord>
so that bounding.mk, after being generated, has one of those stanzas for each country.
3a. Makefile: Then, add this to the beginning of your makefile:
-include bounding.mk
3b. Then add this rule to the end of your makefile:
bounding.mk: dataset.out
convert-to-makefile $< > $#
3c. Then you can write your rules like this:
all: $(COUNTRIES:%=%_crop.tif)
%_crop.tif: ETOPO1_Ice_g_geotiff.tif
gdal_translate -projwin $($*-WEST) $($*-NORTH) $($*-EAST) $($*-SOUTH) $< $#
That should about do it!
I would like to create 4 build options for building Actionscript files. One for Building and one for Running in Linux, and the same for Windows.
Is it possible to do this?
Currently it seems 'windows' and 'linux' sections can only overwrite the default build option?
My current broken .sublime-build file is:
{
"selector": "source.actionscript",
"windows":
{
"cmd": [
"${packages}\\User\\Flash-build.bat",
"${project_path}",
"${file}"
],
"variants":
[
{
"name": "Run",
"cmd": [
"${packages}\\User\\Flash-run.bat",
"${file_path}",
"${file_base_name}"
]
}
],
},
"linux":
{
"cmd": [
"${packages}/User/Flash-build.sh",
"${packages}",
"${project_path}",
"${file_path}",
"${file_base_name}"
],
"variants":
[
{
"name": "Run",
"cmd": [
"${packages}/User/Flash-run.sh",
"${packages}",
"${project_path}",
"${file_path}",
"${file_base_name}"
]
}
]
}
}
Looking at the documentation, I can't see why your solution wouldn't work, however, I know that the following works for me.
Sublime preference files can be specified on a per-OS basis. You could create three separate files:
User/actionscript (OSX).sublime-build
User/actionscript (Linux).sublime-build
User/actionscript (Windows).sublime-build
Sublime will only pick up the one that is relevant to your OS.