Dear Stackoverflow team,
I'm impressed that after a bunch of hours digging the forum I still can't find any question/answer similar to my problem :
I have a GeoJson with a lot of Points features. I collect all Points (green in my example, see figure below) that follow some specification (distance between each of them)
Initial Data:
and I want to link all of them to build a Polygon (which represent an area).
What I'm looking for :
Or Solution accepted :
So I collect all coordinates from these Points, and to be sure the Polygon follows the GeoJson requirements, I'm using the "rewind" function
from geojson_rewind import rewind
But at the end, whatever I've tried I only get that kind of Polygon:
I probably don't use correctly the "rewind" function?
I'm looking for an (easy) automatic way to link all points together in a "convexion hull"
Thanks a lot for any help !
My initial coordinates are collected in a list :
[[4.3556672, 50.8538851], [4.3542534, 50.8546955], [4.3567798, 50.8547854], [4.3566527, 50.8541356], [4.3574286, 50.8552813], [4.3572234, 50.8551264], [4.3547752, 50.8545063], [4.3572736, 50.8560176], [4.3571226, 50.8546104]]
and the Polygon GeoJson I've managed to build, with the rewind function (recopying the last coordinates to get a Polygon) looks like that :
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
4.357223,
50.855126
],
[
4.35678,
50.854785
],
[
4.355667,
50.853885
],
[
4.356653,
50.854136
],
[
4.357123,
50.85461
],
[
4.354253,
50.854695
],
[
4.354775,
50.854506
],
[
4.357429,
50.855281
],
[
4.357274,
50.856018
],
[
4.357223,
50.855126
]
]
]
}
}
]
}
The shapely library is very useful for doing these kinds of geometric manipulations.
For generating a polygon of the convex hull of a set of geometries you can use object.convex_hull:
import shapely.geometry as sg
points = [[4.3556672, 50.8538851], [4.3542534, 50.8546955], [4.3567798, 50.8547854], [4.3566527, 50.8541356], [4.3574286, 50.8552813], [4.3572234, 50.8551264], [4.3547752, 50.8545063], [4.3572736, 50.8560176], [4.3571226, 50.8546104]]
polygon = sg.MultiPoint(points).convex_hull
Which results in the following shape:
Converting it into a GeoJSON with the help of shapely.geometry.mapping:
feature_collection = {
"type": "FeatureCollection",
"features": [
{"type": "Feature", "properties": {}, "geometry": sg.mapping(polygon)}
],
}
import json
geojson = json.dumps(feature_collection)
Related
This is probably more complicated as it sounds, at least with Grafana.
I have an experiment, where for every location (1-100) a value is changed over time. I want to show this with a line graph (or a bar graph), where x-axis correspond to the locations (1-100) and y-axis correspond to the average value for this location for the time interval that is set in Grafana in the upper right corner. Data comes from database. Please, suggest me, which type of graph (dashboard) should I choose in Grafana to achieve the goal. I can only see two kinds of them, those with time on x-axis and those of type histogram but none seems to be applicable.
seems Grafana builtin panels only support
time series, which mean x-axis must be 'time' type.
bilibala-echarts-panel
I use this third-part panel bilibala-echarts-panel
https://grafana.com/grafana/plugins/bilibala-echarts-panel/
achieved the goal: x-axis not use time value.
It can use a custom callback function, to handle data and render
setting
in grafana query setting:
format as time series
// time series need 3 column:
time // time or number (can be parse as time)
metric // string: series name
value // number (otherwise got value error)
assign the value to time column.
// it may rander as 1970-01 in table view, but in echart we can read it as number
in echart panel option:
data.series got the grafana data
// convert/adapte it to echart data here.
maybe format as table can have more flexible data,
and parse them in the callback js.
summary
grafana and echart have different theory,
have to understand both of them ,
and do the convert in js.
// bilibala-echarts-panel using echart v4 #2022-07
We have implemented the graph using natel-plotly-panel plugin.
"panels": [
{
"pconfig": {
"traces": [
{
"mapping": {
"color": "64",
"size": null,
"text": "metriccat",
"x": "loccat",
"y": "valuecat",
"z": null
},
"name": "My value",
"show": {
"line": true,
"lines": true,
"markers": false
}
},
...
]
},
"pluginVersion": "7.5.5",
"targets": [
{
"format": "table",
"group": [],
"metricColumn": "none",
"rawQuery": true,
"rawSql": "SELECT\n avg(column_with_values) AS valuecat,\n loc loccat,\n avg(column_with_values) as metriccat\nFROM ... \nWHERE\n $__timeFilter(timestamp)\nGROUP BY loc\n\n",
"select": [
[
{
"params": [
"value"
],
"type": "column"
}
]
],
"timeColumn": "time",
"where": [
{
"name": "$__timeFilter",
"params": [],
"type": "macro"
}
]
},
...
],
"title": "Average Values Along the Locations",
"type": "natel-plotly-panel",
"version": 1
}
]
I want to use traffic flow data to enhance a route with traffic information like the jam factor.
The recommended way seems to get a route, download TMC tiles for all functional classes and areas of the route, and match the route links to the TMC codes in the traffic flow data, e.g. see How to use HERE Maps to develop custom routing algorithms? .
However, the traffic flow documentation (TrafficML_RealTime_Specification_v3.2.2.docx) mentions a tag "SHP/LID" in the Flow Item Description to contain the link id, which could simplify the whole process:
SHP/LID:
LinkID associated with the SHP reference. The linkID will be in
driving direction order; “F” represents travel direction FROM
reference node, “T” represents travel direction TO reference
node (For example, 123456789T or 987654321F).
In my API call I explicitly request shapes (responseattributes=sh) and receive them, but there is no "LID" field given.
https://traffic.api.here.com/traffic/6.2/flow.json?corridor=52.5396895,12.9778897;52.5394964,12.9782331;52.5390244,12.9769778;52.539078,12.976774;52.5392067,12.9762483;52.5395072,12.9750788;52.5396144,12.974714;52.5397754,12.974124;52.5400114,12.9732764;52.5405693,12.9723108;52.5409126,12.9719353;52.5415349,12.97068;52.5416744,12.9694784;52.5404727,12.9654121;52.5387347,12.9640496;52.5384343,12.9646397;52.5380695,12.9651332;52.5379193,12.965219;52.5370181,12.9656482;52.5359452,12.9659379;52.5349581,12.9661417;52.5339067,12.9663348;1000&responseattributes=sh,fc&app_id=xxx&app_code=yyy
{
"RWS": [
{
"RW": [
{
"FIS": [
{
"FI": [
{
"TMC": {
"PC": 10213,
"DE": "Berlin-Spandau",
"QD": "+",
"LE": 4.18578
},
"SHP": [
{
"value": [
"52.55838,12.96583 52.55761,12.96545 52.55705,12.9652 52.55641,12.96494 52.55588,12.96473 52.55577,12.96468 "
],
"FC": 1
},
{
"value": [
"52.55577,12.96468 52.55566,12.96464 "
],
"FC": 1
},
...
{
"value": [
"52.55935,12.96635 52.55838,12.96583 "
],
"FC": 1
}
],
"CF": [
{
"TY": "TR",
"SP": 120,
"SU": 121.78,
"FF": 105,
"JF": 0,
"CN": 0.99
}
]
},
Is there a way to receive permanent ids with the flow data?
There is a similar question and solutions.
Please have a look at below.
Why does not the TMC from traffic data match with the TMC from PDE layers LINK_TMC_FC?
I've updated my project to Swift 3 from 2.3 and I'm getting an interesting object error for dictionaries. I've tried rewriting this literal in a couple different ways to no luck and looked for answers but none so far posted for 3.0...
let jsonRequest: [String: AnyObject] = [
"requests": [
"image": [
"content": imageData
],
"features": [
[
"type": "LABEL_DETECTION",
"maxResults": 10
],
[
"type":"IMAGE_PROPERTIES",
"maxResults": 1
]
]
]
]
Error displayed:
"Contextual type 'AnyObject' cannot be used with dictionary literal"
Can anyone explain to me what needs to be changed? Thanks!
First things first: is this data in proper GeoJSON format?
According to the definition of GeoJSON data, as you can see by the MultiPoint & coordinates, I think it is.
It looks like this:
{
"lang": {
"code": "en",
"conf": 1.0
},
"group": "JobServe",
"description": "Work with the data science team to build new products and integrate analytics\ninto existing workflows. Leverage big data solutions, advanced statistical\nmethods, and web apps. Coordinate with domain experts, IT operations, and\ndevelopers. Present to clients.\n\n * Coordinate the workflow of the data science team\n * Join a team of experts in big data, advanced analytics, and visualizat...",
"title": "Data Science Team Lead",
"url": "http://www.jobserve.com/us/en/search-jobs-in-Columbia,-Maryland,-USA/DATA-SCIENCE-TEAM-LEAD-99739A4618F8894B/",
"geo": {
"type": "MultiPoint",
"coordinates": [
[
-76.8582049,
39.2156213
]
]
},
"tags": [
"Job Board"
],
"spider": "jobserveNa",
"employmentType": [
"Unspecified"
],
"lastSeen": "2015-05-13T01:21:07.240000",
"jobLocation": [
"Columbia, Maryland, United States of America"
],
"identifier": "99739A4618F8894B",
"hiringOrganization": [
"Customer Relation Market Research Company"
],
"firstSeen": "2015-05-13T01:21:07+00:00"
},
I want to visualize this as a "zoomable",viz. interactive, map, as in the examples on the d3js website.
I'm trying to use a tool called mapshaper.org to see an initial visualization of the data in map form, but when I load it up, nothing happens.
To me this doesn't make sense because, according to their website, one can simply
Drag and drop or select a file to import.
Shapefile, GeoJSON and TopoJSON files and Zip archives are supported.
However, in my case it is not working.
Does anyone have any intuition as to what might be going wrong, or a suggestion as to a tool comparable to create a zoomable map out of GeoJSON data?
According to the definition of GeoJSON data, I have what I think constitutes data in that format
Well, you don't have a proper GeoJSON object. Just compare what you've got against the example you've linked. It doesn't even come close. That's why mapshaper doesn't know what to do with the JSON you load into it.
A GeoJSON object with the type "FeatureCollection" is a feature collection object. An object of type "FeatureCollection" must have a member with the name "features". The value corresponding to "features" is an array. Each element in the array is a feature object as defined above.
A feature collection looks like this:
{
"type": "FeatureCollection",
"features": [
// Array of features
]
}
http://geojson.org/geojson-spec.html#feature-collection-objects
A GeoJSON object with the type "Feature" is a feature object. A feature object must have a member with the name "geometry". The value of the geometry member is a geometry object as defined above or a JSON null value. A feature object must have a member with the name "properties". The value of the properties member is an object (any JSON object or a JSON null value). If a feature has a commonly used identifier, that identifier should be included as a member of the feature object with the name "id".
A feature looks like this:
{
"id": "Foo",
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [0, 0]
},
"properties": {
"label": "My Foo"
}
}
http://geojson.org/geojson-spec.html#feature-objects
Here are examples of the different geometry objects a feature can support: http://geojson.org/geojson-spec.html#appendix-a-geometry-examples
Put those two together, it would look like this:
{
"type": "FeatureCollection",
"features": [{
"id": "Foo",
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [0, 0]
},
"properties": {
"label": "My Foo"
}
},{
"id": "Bar",
"type": "Feature",
"geometry": {
"type": "LineString",
"coordinates": [
[100.0, 0.0],
[101.0, 1.0]
]
},
"properties": {
"label": "My Bar"
}
}]
}
That really doesn't look like the JSON you've posted. You'll need to convert that to proper GeoJSON somehow via a custom script or manually. It's a format i've never seen before, sorry to say.
Using freebase how can I find say, all the burrows/subcities of NY? (queens, brooklyn, etc.)
And will it be similar to other cities? Say if I want to know the subdivisions of Prague (Zizkov, Old Town, etc.) or Berlin, etc?
I've tried various combos but haven't hit one yet.
{
"id": "/en/new_york",
"guid": null,
"name": null,
"/location/location/containedby": [
],
"/location/location/contains" : [],
"/location/place_with_neighborhoods/neighborhoods": [
]
}
The property /location/location/contains is the one that you want, but you're going to have two problems:
It's only sparsely populated
It has multiple levels of containment as a hack to work around API limitations
There's not much you can do about #1 unless you want to work on improving the data yourself. For #2, you can subtract the set of locations which are contained in another location in the "contains" set.
Someone might be able to give a better answer but this will get major districts like in NY but probably not for smaller cities which are more like regions.
{
"id": "/en/new_york",
"guid": null,
"name": null,
"/location/location/containedby": [
],
"/location/location/contains" : [
"name": null,
"type": "/location/citytown"
]
}
or to select multiple items that might be it
{
"id": "/en/new_york",
"guid": null,
"name": null,
"/location/location/containedby": [
],
"/location/location/contains" : [
"name": null,
"type|=" : [
"/location/citytown",
"/location/neighborhood",
"/location/administrative_division",
"/location/de_borough",
"/location/place_with_neighborhoods/neighborhoods"
]
]
}