How to get the Bounding box values from a GeoJSON file? - dictionary

I have of GeoJSON file. But problem is, I do not know the projection of this file. Now, I want to overlay on my base map(OSM). How should I do it? This GeoJSON file contains features around Stockholm area. How can i set the bounding box for this? I tried with couple of openlayers example from hosting sites. But, those do not work for me. I got one example which is very similar with what i want, from (http://dev.openlayers.org/releases/OpenLayers-2.11/examples/all-overlays.html). I checked the source code he used bounding box. But problem is, if I remove bounding box this example does not work(I tied with given data with this). I do not know, is there anything wrong with my json file? Bellow, I have given some sample data. Is the format OK? As I told, I tried with different way. Some time i read the json file just fine from script. But, It can not show the featured overlay ed map. Bellow, I gave sample code, that shows how I tried.
{
"type": "FeatureCollection",
"features": [
{ "type": "Feature", "properties": { "FNODE_": 387603, "TNODE_": 387603, "LPOLY_": 0, "RPOLY_": 0, "LENGTH": 89.206900, "ROADS_SWER": 519006, "ROADS_SW_1": 519006, "REF": "", "TYPE": "residential", "ONEWAY": 8224, "BRIDGE": 8224, "MAXSPEED": 0, "LENGTH_M": 89.500000, "ID": 0, "dist_fnode": 13655.200000, "dist_tnode": 13655.200000 }, "geometry": { "type": "LineString", "coordinates": [ [ 676868.875000, 6569872.000000 ], [ 676882.437500, 6569861.000000 ], [ 676894.062500, 6569851.500000 ], [ 676894.500000, 6569844.500000 ], [ 676891.812500, 6569840.500000 ], [ 676887.312500, 6569841.000000 ], [ 676882.187500, 6569843.000000 ], [ 676875.250000, 6569850.000000 ], [ 676868.125000, 6569858.500000 ], [ 676866.500000, 6569867.000000 ], [ 676868.875000, 6569872.000000 ] ] } }
,
{ "type": "Feature", "properties": { "FNODE_": 387723, "TNODE_": 387724, "LPOLY_": 0, "RPOLY_": 0, "LENGTH": 9.581310, "ROADS_SWER": 519163, "ROADS_SW_1": 519163, "REF": "", "TYPE": "service", "ONEWAY": 8224, "BRIDGE": 8224, "MAXSPEED": 0, "LENGTH_M": 9.500000, "ID": 1, "dist_fnode": 13705.100000, "dist_tnode": 13695.600000 }, "geometry": { "type": "LineString", "coordinates": [ [ 677125.375000, 6569906.500000 ], [ 677133.437500, 6569911.500000 ] ] } }
,
..
..
]
}
Code Sample----
//OSM Layer-----------------------------------------------
var layer = new OpenLayers.Layer.OSM( "Simple OSM Map");
//GeoJSON Layer-------------------------------------------
var vector_format = new OpenLayers.Format.GeoJSON({});
var vector_protocol = new OpenLayers.Protocol.HTTP({
url: 'ml/roads.json',
format: vector_format
});
var vector_strategies = [new OpenLayers.Strategy.Fixed()];
var vector_layer = new OpenLayers.Layer.Vector('More Advanced Vector Layer',{
protocol: vector_protocol,
strategies: vector_strategies,
isBaseLayer: false
});
var options = {
layers: [layer, vector_layer]
};
var map = new OpenLayers.Map("map", options);
//Projection-----------------------------------------------
map.setCenter(
new OpenLayers.LonLat(18.068611, 59.329444).transform(
new OpenLayers.Projection("EPSG:4326"),
map.getProjectionObject()
), 10
);
Thanks, in advance.

vector_layer.events.on({
loadend: function() {
map.zoomToExtent(vector_layer.getDataExtent());
}
});
I still think you should set your projection in the map constructor…

Related

How to create widget in a single AWS Cloud Watch dashboard for a list of instances

Terraform (aws provider) beginner here. I am trying to create aws-cloudwatch widget that graphs CPU Utilization for 3 instances. However, I only get one graph generated for the last instance in the list instead three graphs on one widget! How can I fix this please or get this How can I get this code to create CPUUtilisation graph for three instances on the same widget? Thank you
variable "targets" {
default = ["i-086e06769b6c67665","i-0477b6f25ad155290","i-0e6320273511d17dc"]
}
resource "aws_cloudwatch_dashboard" "ec2" {
dashboard_name = "ec2-test-dashboard"
count = length(var.targets)
dashboard_body = <<EOF
{
"widgets": [
{
"type": "metric",
"x": 0,
"y": 0,
"width": 17,
"height": 8,
"properties": {
"metrics": [
["AWS/EC2","CPUUtilization","InstanceId","${(var.targets[count.index])}"]
],
"title": "EC2 dashboard: CPUUtilization",
"stat": "Average",
"period": 300,
"stacked": false,
"view": "timeSeries",
"region": "eu-west-1",
"annotations": {
"horizontal": [
{
"label": "critical range",
"value": 10
}
]
},
"legend": {
"position": "right"
}
}
}
]
}
EOF
}

Not able to filter out required property in Azure TSI Gen1 Get Events API response

I am using the below request body to fetch only the required property values.
"searchSpan": {
"from": {
"dateTime": "2021-11-20T00:00:00.000Z"
},
"to": {
"dateTime": "2021-11-20T23:00:00.000Z"
}
},
"predicateString": "[Params.Name] = 'power'",
"take": 100
}
}
The URL is like below:
https://12345678a-bcde-3e91-blah-2292933292aa.env.timeseries.azure.com/events?api-version=2016-12-12
Despite specifying the required property the response returns all properties as if it has not seen the predicate string. What might I be doing wrong?
{
"warnings": [],
"events": [
{
"schema": {
"rid": 0,
"$esn": "my-event-hub",
"properties": [
{
"name": "mytimestamp",
"type": "DateTime"
},
{
"name": "Params.Name",
"type": "String"
},
{
"name": "Params.Value",
"type": "Double"
}
]
},
"$ts": "2021-11-20T10:01:50Z",
"values": [
"2021-11-20T10:01:50Z",
"energy",
60
]
},
{
"schemaRid": 0,
"$ts": "2021-11-20T10:01:50Z",
"values": [
"2021-11-20T10:01:50Z",
"power",
10
]
},
{
"schemaRid": 0,
"$ts": "2021-11-20T10:01:50Z",
"values": [
"2021-11-20T10:01:50Z",
"strength",
200
]
},
]
}
Edit
I'm getting "Properties count error" in the TSI overview page. This might quite be the root cause but I don't know for sure
"For Time Series Insights environment ABC: You have used all 641/600 properties in your environment".

How to write this Fulfillment codes(including output)?

First of all, I tried to write how to save users input data to google sheet after developing the simple codes. It's able to work. Thank Mr.Master for providing this tutorial(Below the link).
Reference Mr.Master: https://www.youtube.com/watch?v=huwUpJZsTok
Next, I bumped into the problem below the code. I didn't know how to write it in Fulfillment. Could someone realize it to teach me?
Tool: Dialogflow, Google sheet, Firebase.
Theme: Order process
I tried to write Forhere() there. However, it didn't work.(First code)
function Forhere(agent){
const{
forhere, howmanypeople, whattime, namelist
} = agent.parameters;
const data1 = [{
Forhere: forhere,
HowManyPeople: howmanypeople,
Time: whattime,
Name: namelist
}];
axios.post('......', data1);
}
{/*....This code is a result of test(second one)
"responseId": "d0f44937-e58a-4b71-b6dc-ec2d6c39337b-f308a5c4",
"queryResult": {
"queryText": "黃大哥",
"parameters": {
"forhere": [
"內用"
],
"howmanypeople": [
2
],
"whattime": [
**{
"date_time": "2019-09-19T14:00:00+08:00"
}**
],
"namelist": [
"黃大哥"
]
},
"allRequiredParamsPresent": true,
"outputContexts": [
{
"name": "projects/test-tyrpxs/agent/sessions/5dd26d5c-bd99-072c-3693-41f95a3a348d/contexts/forhere",
"lifespanCount": 4,
"parameters": {
"howmanypeople": [
2
],
"namelist.original": [
"黃大哥"
],
"howmanypeople.original": [
"2"
],
"forhere": [
"內用"
],
"whattime.original": [
"明天下午2點"
],
"welcome": "嗨",
"whattime": [
{
"date_time": "2019-09-19T14:00:00+08:00"
}
],
"namelist": [
"黃大哥"
],
"welcome.original": "hi",
"forhere.original": [
"內用"
]
}
}
],
"intent": {
"name": "projects/test-tyrpxs/agent/intents/ec0f55c4-e9c9-401f-bce7-d2478c40fb85",
"displayName": "ForHere"
},
"intentDetectionConfidence": 1,
"diagnosticInfo": {
"webhook_latency_ms": 4992
},
"languageCode": "zh-tw"
},
"webhookStatus": {
"code": 4,
"message": "Webhook call failed. Error: Request timeout."
}
}
You can use below code
let forhere= agent.parameters.forhere;
let howmanypeople= agent.parameters.howmanypeople;
let whattime= agent.parameters.whattime;
let namelist= agent.parameters.namelist;
then use this variables in your api call.
To T.Ali:
Dialogflowfirebasefulfillment&Error message:
Although I think this error didn't show where these mistakes are.
Dialogflow Request body: {"responseId":"ab277bc6-3bcc-4c4b-9a94-192b9ecfb8af-f308a5c4","queryResult":{"queryText":"黃大哥","parameters":{"forhere":"內用","whattime":{"date_time":"2019-09-20T12:00:00+08:00"},"howmanypeople":3,"namelist":"黃大哥"},"allRequiredParamsPresent":true,"outputContexts":[{"name":"projects/test-tyrpxs/agent/sessions/5dd26d5c-bd99-072c-3693-41f95a3a348d/contexts/forhere","lifespanCount":4,"parameters":{"welcome":"嗨","welcome.original":"hi","forhere":"內用","forhere.original":"內用","whattime":{"date_time":"2019-09-20T12:00:00+08:00"},"whattime.original":"明天中午","howmanypeople":3,"howmanypeople.original":"3","namelist":"黃大哥","namelist.original":"黃大哥"}}],"intent":{"name":"projects/test-tyrpxs/agent/intents/ec0f55c4-e9c9-401f-bce7-d2478c40fb85","displayName":"ForHere"},"intentDetectionConfidence":1,"languageCode":"zh-tw"},"originalDetectIntentRequest":{"payload":{}},"session":"projects/test-tyrpxs/agent/sessions/5dd26d5c-bd99-072c-3693-41f95a3a348d"}
Error: No handler for requested intent
at WebhookClient.handleRequest (/srv/node_modules/dialogflow-fulfillment/src/dialogflow-fulfillment.js:317:29)
at exports.dialogflowFirebaseFulfillment.functions.https.onRequest (/srv/index.js:105:9)
at cloudFunction (/srv/node_modules/firebase-functions/lib/providers/https.js:57:9)
at /worker/worker.js:783:7
at /worker/worker.js:766:11
at _combinedTickCallback (internal/process/next_tick.js:132:7)
at process._tickDomainCallback (internal/process/next_tick.js:219:9)
Furthermore, I've write below the code worked formally(input users data to google sheet).
enter image description here

Create product variations with python woocommerce api

I am attempting to create a product with variations in WooCommerce but I am getting this error:
{u'message': u'No route was found matching the URL and request method', u'code': u'rest_no_route', u'data': {u'status': 404}}
when I run the create_variation function from the API.
I ran a GET on the attributes for the product I created and it found no attributes even though the printed response when I created the product had the attributes listed.
Here is my code to create the variable product:
data = {
"name": row[3],
"type": "variable",
"description": row[4],
"images": [
{
"src": row[15],
"position": 0
}
],
"in_stock": True,
"sku": row[2],
'attributes': [
{
'name': 'Size',
'variation': True,
'visible': True,
'options': sizeList,
},
{
'name': 'Color',
'variation': True,
'visible': True,
'options': colorList,
}
],
}
print(wcapiNew.post("products", data).json())
Here is my code to create the variations:
result = wcapi.get("products/sku/"+row[2]).json()
product_id = result['product']['id']
variationData = {
"regular_price": row[17],
"image": {
"src": row[13]
},
"sku": row[19],
"attributes": [
{
"name": "Color",
"option": row[6]
},
{
"name": "Size",
"option": row[10]
}
]
}
print(wcapiNew.post("products/"+str(product_id)+"/variations", variationData).json())
I've been tearing my hair out trying to figure out what I'm doing wrong but I'm clueless right now.
Any help is appreciated. Thanks.
This is my variations data, and it work.
data_1 = {
"regular_price": "9.00",
"sku": "premium-quality-101-red",
"attributes": [
{
"id": 1,
"option": "Red"
}]
}
I figure out that you need to use id, and update one variation at a time.

How to read external GeoJSON file from openlayers?

I have to draw some lines by OpenLayers. The line features are coded as GeoJSON format. My code is ok for hard coded GeoJSON features. But, if I put this features in separate file and try to load it. It just does not work. I do not know what is the wrong with my loading external GeoJSON file. I have given both the code.
Code 1:
// This code is ok with hard coded GeoJSON features
map.addControl(new OpenLayers.Control.LayerSwitcher());
vectorLayer = new OpenLayers.Layer.Vector("Lines");
var myGeoJSON = { "type": "FeatureCollection",
"features":
[
{ "type": "Feature", "properties": { "LENGTH": 756.304000}, "geometry": { "type": "LineString", "coordinates": [ [ 18.105018, 59.231027 ], [ 18.104176, 59.230737 ], [ 18.103928, 59.230415 ], [ 18.103650, 59.230336 ], [ 18.103028, 59.230463 ], [ 18.102491, 59.230418 ], [ 18.101976, 59.230237 ], [ 18.100893, 59.230110 ], [ 18.100117, 59.230016 ], [ 18.097715, 59.230262 ], [ 18.096907, 59.230376 ], [ 18.096637, 59.230405 ], [ 18.096578, 59.230428 ], [ 18.096429, 59.230450 ], [ 18.096336, 59.230479 ], [ 18.096108, 59.230534 ], [ 18.095971, 59.230600 ], [ 18.095925, 59.230633 ], [ 18.095891, 59.230665 ], [ 18.094000, 59.231676 ], [ 18.093864, 59.231720 ] ] } }
,
{ "type": "Feature", "properties": { "LENGTH": 1462.390000}, "geometry": { "type": "LineString", "coordinates": [ [ 17.877073, 59.461653 ], [ 17.877116, 59.461598 ], [ 17.876936, 59.461507 ], [ 17.876936, 59.461323 ], [ 17.876773, 59.461098 ], [ 17.876430, 59.460885 ], [ 17.876413, 59.460553 ], [ 17.876576, 59.460280 ], [ 17.876575, 59.460078 ], [ 17.876762, 59.460060 ], [ 17.877371, 59.460042 ], [ 17.877808, 59.460046 ], [ 17.878641, 59.460046 ], [ 17.879010, 59.460078 ], [ 17.879337, 59.460044 ], [ 17.879526, 59.459878 ], [ 17.879749, 59.459563 ], [ 17.880058, 59.459538 ], [ 17.880435, 59.459503 ], [ 17.887550, 59.453608 ], [ 17.887696, 59.453430 ], [ 17.887971, 59.453150 ], [ 17.888221, 59.452843 ], [ 17.888246, 59.452721 ], [ 17.888435, 59.452609 ], [ 17.888470, 59.452568 ], [ 17.888517, 59.452410 ] ] } }
]
};
var geojson_format = new OpenLayers.Format.GeoJSON({
'internalProjection': map.baseLayer.projection,
'externalProjection': new OpenLayers.Projection("EPSG:4326")
});
map.addLayer(vectorLayer);
vectorLayer.addFeatures(geojson_format.read(myGeoJSON));
map.setCenter(
new OpenLayers.LonLat(18.068611, 59.329444).transform(
new OpenLayers.Projection("EPSG:4326"),
map.getProjectionObject()
), 10
);
Code 2: This code shows an error that it could not load features
//This code does not work because it can not load the external GeoJSON file
map.addControl(new OpenLayers.Control.LayerSwitcher());
vectorLayer = new OpenLayers.Layer.Vector("Lines");
var myGeoJSON = new OpenLayers.Layer.Vector("Lines", {
strategies: [new OpenLayers.Strategy.Fixed()],
protocol: new OpenLayers.Protocol.HTTP({
url: "ml/lines.json"
})
});
var geojson_format = new OpenLayers.Format.GeoJSON({
'internalProjection': map.baseLayer.projection,
'externalProjection': new OpenLayers.Projection("EPSG:4326")
});
map.addLayer(vectorLayer);
vectorLayer.addFeatures(geojson_format.read(myGeoJSON));
map.setCenter(
new OpenLayers.LonLat(18.068611, 59.329444).transform(
new OpenLayers.Projection("EPSG:4326"),
map.getProjectionObject()
), 10
);
Thanks in advance
geojson_layer = new OpenLayers.Layer.Vector("GeoJSON", {
strategies: [new OpenLayers.Strategy.Fixed()],
protocol: new OpenLayers.Protocol.HTTP({
url: "ml/lines.json",
format: new OpenLayers.Format.GeoJSON()
})
});
See my little example.

Resources