combining multiple geojson files w tsv and preserving property with topojson - d3.js

i'm trying to do many things w topojson… combine 2 geojson files w 1 tsv, join on ELECT_DIV n NAME, promote that to the id, and keep 2012_POP from the tsv.
here's the command i'm using:
topojson -o electorates.json -e 2012_oz_population.tsv --id-property ELECT_DIV,NAME -p 2012_POP -s .0000005 --allow-empty -- electorates.geojson region.geojson
ELECT_DIV is in electorates.geojson. it is getting set as the ID on all the features, but each one is not getting the proper 2012_POP from the join with the tsv. however, at the top level, electorates and region are getting the last value of 2012_POP from the tsv, so it's joining in some way...
any ideas on what i'm doing wrong? do i need to do this in more than one topo command?
thanks!
UPDATE W REQUESTED INFO
2012_oz_population.tsv
CED_CODE NAME 2011_POP 2012_POP
101 Banks 154938 156527
electorates.geojson
"features": [
{ "type": "Feature", "properties": { "ELECT_DIV": "Lingiari", "STATE": "NT", "NUMCCDS": 335.0, "ACTUAL": 0.0, "PROJECTED": 0.0, "POPULATION": 0.0, "OVER_18": 0.0, "AREA_SQKM": 1352034.05, "SORTNAME": "Lingiari" }, "geometry": { "type": "MultiPolygon",
region.geojson
"features": [
{ "type": "Feature", "properties": { "scalerank": 5, "featurecla": "Admin-0 country", "labelrank": 5.0, "sovereignt": "Australia", "sov_a3": "AU1", "adm0_dif": 1.0, "level": 2.0, "type": "Dependency", "admin": "Ashmore and Cartier Islands", "adm0_a3": "ATC", "geou_dif": 0.0, "geounit": "Ashmore and Cartier Islands", "gu_a3": "ATC", "su_dif": 0.0, "subunit": "Ashmore and Cartier Islands", "su_a3": "ATC", "brk_diff": 0.0, "name": "Ashmore and Cartier Is.", "name_long": "Ashmore and Cartier Islands", "brk_a3": "ATC", "brk_name": "Ashmore and Cartier Is.", "brk_group": null, "abbrev": "A.C.Is.", "postal": "AU", "formal_en": "Territory of Ashmore and Cartier Islands", "formal_fr": null, "note_adm0": "Auz.", "note_brk": null, "name_sort": "Ashmore and Cartier Islands", "name_alt": null, "mapcolor7": 1.0, "mapcolor8": 2.0, "mapcolor9": 2.0, "mapcolor13": 7.0, "pop_est": -99.0, "gdp_md_est": -99.0, "pop_year": -99.0, "lastcensus": -99.0, "gdp_year": -99.0, "economy": "7. Least developed region", "income_grp": "5. Low income", "wikipedia": -99.0, "fips_10": null, "iso_a2": "-99", "iso_a3": "-99", "iso_n3": "036", "un_a3": "-099", "wb_a2": "-99", "wb_a3": "-99", "woe_id": -99.0, "adm0_a3_is": "AUS", "adm0_a3_us": "ATC", "adm0_a3_un": -99.0, "adm0_a3_wb": -99.0, "continent": "Oceania", "region_un": "Oceania", "subregion": "Australia and New Zealand", "region_wb": "East Asia & Pacific", "name_len": 23.0, "long_len": 27.0, "abbrev_len": 7.0, "tiny": -99.0, "homepart": -99.0 }, "geometry": { "type": "Polygon", "coordinates":
now that ive written that out (and figured out how to do basic markdown in Stackoverflow like a clown), i wonder, is it getting caught up on the join of the name in region.geojson?
thx much for the help #mbostock

so embarrassingly (as this has happened before to me), this was because i was using an outdated version of topojson.
after i updated the version to 1.2.3 (using npm update -g topojson) the properties mapped appropriately with the above command.
thx for responding regardless mike. i feared it was something on my end. alas, it was.

Related

Elasticsearch - Sort By Distance Not Working?

I have an index where the records are stored in the following format:
"_source": {
"name": "ACME Pallets",
"about": null,
"slug": "acme-pallets",
"serviceAreas": [
{
"admin1": "usa",
"admin2": null,
"admin3": null,
"admin4": null,
"countryCode": "US",
"googlePlaceId": null,
"locality": null,
"selectedLevel": "admin1"
}
],
"id": "fadsflsjdfkk3234234",
"addresses": [
{
"address1": "4342 Dietrich Rd",
"address2": null,
"city": "San Antonio",
"countryCode": "US",
"latitude": 29.44122,
"longitude": -98.34404,
"primary": true,
"name": "office",
"postal": "78219",
"province": "TX",
"location": {
"lat": 29.44156,
"lon": -98.37704
}
}
]
}
I am trying to return results from this index where the records are sorted by distance to the search point I pass in. My sort config being passed in looks like this:
_geo_distance: {
'addresses.location': { lat: 31.75917, lon: -106.48749 },
order: 'asc',
unit: 'mi',
mode: 'min'
}
The results I receive back are not sorted according to distance. If I manually plot out the individual locations on a map and the search pin passed in, I can see that the sorting is out of order.
If I pass in a sorting config to my search to sort by alphabetically order or to sort by relevance (aka _score), the sorting returned is correct.
Does anyone know why ES might be returning my results incorrectly when sorting by distance?
addresses is an array in my index. Each object inside of addresses has a property called location of type geo_point.
From all the documentation that I've read, passing 'addresses.location': { lat: 31.75917, lon: -106.48749 } into the search should work, but it doesn't. ES should be smart enough to find the location geo point in each object and use that as the reference when calculating the distance. If there are more than one object inside of the addresses array, then ES by default should get the center point of all the objects inside of addresses and use that to calculate the distance from the search point.
In my case, I don't have any data where addresses has more than one object. I ended up creating a location geo_point property outside of the addresses property during index build and then passing in location: { lat: 31.75917, lon: -106.48749 } for the search. This made ES sort results based on distance correctly.
What my new index looks like with the added location property:
"_source": {
"name": "ACME Pallets",
"about": null,
"slug": "acme-pallets",
"serviceAreas": [
{
"admin1": "usa",
"admin2": null,
"admin3": null,
"admin4": null,
"countryCode": "US",
"googlePlaceId": null,
"locality": null,
"selectedLevel": "admin1"
}
],
"id": "fadsflsjdfkk3234234",
"addresses": [
{
"address1": "4342 Dietrich Rd",
"address2": null,
"city": "San Antonio",
"countryCode": "US",
"latitude": 29.44122,
"longitude": -98.34404,
"primary": true,
"name": "office",
"postal": "78219",
"province": "TX",
"location": {
"lat": 29.44156,
"lon": -98.37704
}
}
]
"location": {
"lat": 29.44156,
"lon": -98.37704
}
}

Sorting on runtime calculated price value?

we have day prices in our index. When user search for 7 nights we show the total price (7*nightprice = totalprice). We want to sort on total_price value.
The process and issue.
First we call our Index API to search appropriate accommodations by checking availabilities, restrictions etc. After that we get accommodations from our API, we pass searched accommodations ids to our Prices API to get they dynamic price. We are using ElasticSearch custom DSLs for our search. Now, we need to sort accommodations based on dynamic prices while keeping pagination on server side, but we can only sort accommodations that are visible on our first page because of dynamic prices are calculated in a separate API.
First call (Index API)
{
"id": "6555",
"type": "lodging",
"attributes": {
"id": 6555,
"name": "Villa Georges",
"h1": "Villa Georges | Stijlvol herenhuis in het hart van Rochefort in de Ardennen",
"h2": "",
"lodging_type": "villa",
"slug": "villa-georges",
"presentation": "as_standalone",
"child_name": "Villa Georges",
"country_name": "België",
"region_name": "Namen",
"address": "",
"latitude": 50.158783,
"longitude": 5.222144,
"adults": 8,
"children": null,
"infants": 1,
"price": 314,
"calculated_price": null,
"dynamic_price": null,
"short_desc": "",
"images": [
"https://imagesnice2stayeurope.s3.amazonaws.com/uploads/image/image/54634/Z6A0837-min.jpg",
"https://imagesnice2stayeurope.s3.amazonaws.com/uploads/image/image/54626/Z6A0753-min.jpg"
],
"average_rating": 0.0,
"created_at": "2021-02-01T00:00:00.000Z",
"updated_at": "2022-06-14T16:58:06.917Z",
"highlight_1": "Winkels en restaurants op loopafstand",
"highlight_2": "Mooie tuin rondom ",
"highlight_3": "Stijlvolle inrichting ",
"beds": 4,
"baths": 2,
"channel": "standard",
"particularities_text": "<ul>\r\n\t<li>Aankomst is flexibel met een minimum van 2 nachten </li>\r\n\t<li>Inchecken is mogelijk vanaf 14 uur, check-out voor 12 uur op de dag van vertrek</li>\r\n\t<li>Binnen mag er niet worden gerookt, buiten op de aangewezen plekken</li>\r\n\t<li>Kinderstoel, kinderbedje wordt klaargezet op aanvraag</li>\r\n\t<li>Huisdieren zijn niet toegestaan</li>\r\n\t<li>Zelf inchecken met sleutelkastje</li>\r\n</ul>\r\n",
"open_gds_property_id": null,
"open_gds_accommodation_id": null,
"including_text": "<ul>\r\n\t<li>gas/water/elektriciteit </li>\r\n\t<li>linnen, handdoeken, badjassen</li>\r\n\t<li>verzorgingsproducten</li>\r\n\t<li>wifi </li>\r\n\t<li>kinderbedje en stoel </li>\r\n</ul>\r\n",
"setting": 0.0,
"quality": 0.0,
"interior": 0.0,
"service": 0.0,
"communication": 0.0,
"total_reviews": 0,
"lowest_child_price": 314,
"total_available_childrens": 0,
"first_available_child_id": null
}
}
Second call (price API). The calculated_price is calculated on runtime.
{
"id": "6555",
"type": "cumulative_price",
"attributes": {
"id": 6555,
"name": "Villa Georges",
"calculated_price": 3325.0,
"price_valid": true,
"price_errors": {},
"dynamic_price": true,
"check_in": "2022-07-12",
"check_out": "2022-07-19",
"discount_price": 0.0,
"rent_price": 3325.0,
"cleaning_cost": 0.0,
"belongs_to_channel": false,
"optional_supplements": {
"data": []
},
"mandatory_supplements": {
"data": []
}
}
},
Any suggestions ?
best remco

Google Places API: different output for textsearch and nearbysearch (formatted_address missing)

Want to use Google Places API nearby search for reverse lookup using coordinates.
I use nearbysearch endpoint.
https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=-33.892674%2C151.200727&rankby=distance&type=bar&key=...
What is missing is formatted_address.
When trying to use textsearch instead, I do get formatted_address.
https://maps.googleapis.com/maps/api/place/textsearch/json?location=-33.892674%2C151.200727&rankby=distance&type=bar&key=...
Both return the same first place_id and look very similar.
Differences I noticed:
textsearch: formatted_address, empty opening_hours are included
nearbysearch: vicinity, scope, empty opening_hours are not included
How do I get formatted_address?
Update: I checked and both types should return the same fields.
details
When searching by distance & type I guess I could use either nearbysearch or textsearch, but when searching by prominence I will have to use nearbysearch as textsearch requires either type or query.
The query I would like to use (using nearbysearch, so missing formatted_address):
https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=-33.892674%2C151.200727&rankby=prominence&radius=500&key=...
Full output textsearch
{
"business_status": "OPERATIONAL",
"formatted_address": "7 Cope St, Redfern NSW 2016",
"geometry": {
"location": {
"lat": -33.892682,
"lng": 151.20075
},
"viewport": {
"northeast": {
"lat": -33.89147812010727,
"lng": 151.2019769298927
},
"southwest": {
"lat": -33.89417777989272,
"lng": 151.1992772701072
}
}
},
"icon": "https://maps.gstatic.com/mapfiles/place_api/icons/bar-71.png",
"id": "d8b3f319ad00fafd66527b248e450284a53386c2",
"name": "Arcadia",
"opening_hours": {
"open_now": true
},
"photos": [
{
"height": 3000,
"html_attributions": [
"Colin Hannah"
],
"photo_reference": "CmRaAAAAvnYeIFoCoiiQoyRqKQqpz1yJK71eXM3wYuCiTFTTtj3iwTiIW_z865AfLogqMiEyyBh5GqZoxAcHDmzyE8KelhGEh3C-ggm5LQDGK4zFWxdTNCholvXurq0ce7zLoztgEhBgklqzYxK5jhDhwqB5wuabGhQRUb448z5zV9l7EDSmXLMo5icv1w",
"width": 4000
}
],
"place_id": "ChIJ3Y3vQdqxEmsRTvCcbZnsYJ8",
"plus_code": {
"compound_code": "4642+W7 Redfern, New South Wales",
"global_code": "4RRH4642+W7"
},
"price_level": 2,
"rating": 4.5,
"reference": "ChIJ3Y3vQdqxEmsRTvCcbZnsYJ8",
"types": [
"bar",
"point_of_interest",
"establishment"
],
"user_ratings_total": 279
},
Full output nearbysearch:
{
"business_status": "OPERATIONAL",
"geometry": {
"location": {
"lat": -33.892682,
"lng": 151.20075
},
"viewport": {
"northeast": {
"lat": -33.8914789697085,
"lng": 151.2019760802915
},
"southwest": {
"lat": -33.89417693029149,
"lng": 151.1992781197085
}
}
},
"icon": "https://maps.gstatic.com/mapfiles/place_api/icons/bar-71.png",
"id": "d8b3f319ad00fafd66527b248e450284a53386c2",
"name": "Arcadia",
"opening_hours": {
"open_now": true
},
"photos": [
{
"height": 3024,
"html_attributions": [
"Milan"
],
"photo_reference": "CmRaAAAA7u4ZpZOddZ8ypuGySsQ1lG0HEX4Ke0DHeYtHYN1gEchx-yf1U-DVLNHVdmFVLoocHbMmWlMVCqcW9oMnpDC4-dw6ObZAovVQG90GpVD3sYeMEpzBB80yjhttjZ1lsIEdEhCzQJane_k8xy-HlI9ZlE9WGhQJ13KgR88Q239e8ocBCt5H0BgpKQ",
"width": 4032
}
],
"place_id": "ChIJ3Y3vQdqxEmsRTvCcbZnsYJ8",
"plus_code": {
"compound_code": "4642+W7 Redfern NSW, Australia",
"global_code": "4RRH4642+W7"
},
"price_level": 2,
"rating": 4.5,
"reference": "ChIJ3Y3vQdqxEmsRTvCcbZnsYJ8",
"scope": "GOOGLE", <===========
"types": [
"bar",
"point_of_interest",
"establishment"
],
"user_ratings_total": 279,
"vicinity": "7 Cope Street, Redfern" <===========
},
Comment from #MrUpsidown points to the documentation where it is stated:
A Text Search response is similar, except that it returns a formatted_address instead of a vicinity property
So, it seems that's just the way it is.
"formatted_address": "7 Cope St, Redfern NSW 2016",
vs
"vicinity": "7 Cope Street, Redfern"

Add a geojson file on a OSM map

I want to put a geojson file on my open street map for have a marker ( place )
my geojson file looks like :
{ "type": "Feature", "properties": { "#id": "way\/76732062", "access": "customers", "amenity": "bicycle_parking", "bicycle_pa": "shed", "building": "yes", "capacity": "45", "name": "Vélopole - Les Près", "source": "cadastre-dgi-fr source : Direction Générale des Impôts - Cadastre. Mise à jour : 2009", "operator": null, "network": null, "surveillan": null, "wall": null, "covered": null, "supervised": null, "fee": null, "lit": null, "level": null }, "geometry": { "type": "Point", "coordinates": [ 708894.79501892452, 7061474.7829677835 ] } },
being a junior developer I absolutely do not know how to add this file to my map
i see many exmaples like :
$.getJSON("http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_day.geojson", function(data) { addDataToMap(data, map); });
but I do not know how to adapt it to my code
Thank's in advance for ur answer !

Is three.js ObjectLoader capable of loading textures?

three.js version 0.0.70, blender version 2.73a
I have a scene exported from blender to three.js json format using new io_three (not io_three_mesh) exporter.
I'm able to import the scene into three.js using ObjectLoader:
var objectLoader = new THREE.ObjectLoader();
objectLoader.load('assets/models/exportedScene.json', function(imported) {
scene.add(imported);
});
Unfortunatelly, no texture is applied to an object, only the material.
As I see from exportedScene.json file, there is an info about texture in file:
"images": [{
"url": "blue.jpg",
"uuid": "DFE5BBBF-601B-48EA-9C05-B9CB9C07D92E",
"type": "Geometry",
"name": "blue.jpg"
}],
"materials": [{
"color": 200962,
"specular": 5066061,
"shininess": 8,
"ambient": 200962,
"depthTest": true,
"depthWrite": true,
"name": "partitionMat",
"emissive": 0,
"uuid": "A705A33F-68C1-489C-A702-89A0140247AB",
"blending": "NormalBlending",
"vertexColors": false,
"map": "73277351-6CCF-4E84-A9F0-D275A101D842",
"type": "MeshPhongMaterial"
}],
"textures": [{
"minFilter": "LinearMipMapLinearFilter",
"wrap": ["RepeatWrapping","RepeatWrapping"],
"magFilter": "LinearFilter",
"mapping": "UVMapping",
"image": "DFE5BBBF-601B-48EA-9C05-B9CB9C07D92E",
"repeat": [1,1],
"name": "carpetTexture",
"anisotropy": 1.0,
"uuid": "73277351-6CCF-4E84-A9F0-D275A101D842",
"type": "Geometry"
}],
But as I said before, no texture is applied.
I tried placing texture file near the html with js script, but it didn't work.
Maybe my initial approach is incorrect and I should import textures similar to http://threejs.org/examples/webgl_loader_obj.html? However, this one is about using ObjLoader (not ObjectLoader), and I'm not sure if it's correct.
Check out the dev branch. There have been recent commits for texture support for the upcoming r71 release.
Latest format support it like following:
"images":[
{
"uuid": "A430CF4-AD77-11E3-914E-00248C62C323",
"url": "../models/1024_tornis.png"
},
{
"uuid": "eka_tv_2_i",
"url": "../models/eka_tv_2.jpg"
},
{
"uuid": "sala_model_0709_map_i",
"url": "../models/sala_model_0709_map.png"
}
],
"textures":[
{
"uuid": "1024_tornis",
"image": "A430CF4-AD77-11E3-914E-00248C62C323"
},
{
"uuid": "eka_tv_2",
"image": "eka_tv_2_i"
},
{
"uuid": "sala_model_0709_map",
"image": "sala_model_0709_map_i"
}
],
"materials": [
{
"uuid": "3C5CA6AA-055B-417B-97E0-706BA446140B",
"type": "MeshLambertMaterial",
"name": "Material.001",
"color": 16777215,
"emissive": 0,
"map": "1024_tornis"
}]

Resources