Last active
July 13, 2020 19:48
-
-
Save vesse/007e0d0e2bfafeb917efb0d60fbb6a5c to your computer and use it in GitHub Desktop.
Revisions
-
vesse renamed this gist
Jul 13, 2020 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
vesse revised this gist
Jul 13, 2020 . 1 changed file with 7 additions and 12 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,3 @@ import axios from 'axios'; import * as proj4 from 'proj4'; @@ -43,9 +40,7 @@ const polygon: [number, number][] = [ ]; const filter = getFilter( polygon.map(([lat, lon]) => proj4('WGS84', 'TM35FIN', [lon, lat])) ); const endpoint = 'http://geo.stat.fi/geoserver/postialue/wfs'; @@ -57,18 +52,18 @@ const params = new URLSearchParams({ outputFormat: 'json', typeName: 'postialue:pno', filter, propertyName: 'posti_alue', }); if (!module.parent) { axios .get(endpoint, { params }) .then((response) => response.data) .then((geojson: Result) => geojson.features .map((feature) => feature.properties.posti_alue) .join('\n') ) .then(console.log) .catch(console.error); } -
vesse created this gist
Jul 13, 2020 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,74 @@ /** * Quick and dirty test only */ import axios from 'axios'; import * as proj4 from 'proj4'; interface Result { readonly features: ReadonlyArray<{ readonly properties: { readonly posti_alue: string; }; }>; } proj4.defs( 'TM35FIN', '+proj=utm +zone=35 +ellps=GRS80 +towgs84=0,0,0,-0,-0,-0,0 +units=m +no_defs' ); const getFilter = (coordinates: [number, number][]) => ` <ogc:Filter xmlns:ogc="http://www.opengis.net/ogc"> <ogc:Intersects> <ogc:PropertyName>geom</ogc:PropertyName> <gml:Polygon xmlns:gml="http://www.opengis.net/gml" srsName="EPSG:3067"> <gml:exterior> <gml:LinearRing> <gml:posList> ${coordinates.map((coordinate) => coordinate.join(' ')).join(' ')} </gml:posList> </gml:LinearRing> </gml:exterior> </gml:Polygon> </ogc:Intersects> </ogc:Filter> `; const polygon: [number, number][] = [ [61.511309, 23.726957], [61.513618, 23.786633], [61.491548, 23.797155], [61.490941, 23.737657], [61.511309, 23.726957], ]; const filter = getFilter( polygon.map(([lat, lon]: [number, number]) => proj4('WGS84', 'TM35FIN', [lon, lat]) ) ); const endpoint = 'http://geo.stat.fi/geoserver/postialue/wfs'; const params = new URLSearchParams({ service: 'wfs', version: '1.1.0', request: 'GetFeature', srsName: 'EPSG:3067', outputFormat: 'json', typeName: 'postialue:pno', filter, }); if (!module.parent) { axios .get(endpoint, { params }) .then((response) => response.data) .then((geojson: Result) => geojson.features.forEach((feature) => console.log(feature.properties.posti_alue) ) ) .catch((err) => { console.error('Failed', err); }); }