Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const GeoJSON = require('./geojson');
- const data = [
- { name: 'Location A', category: 'Store', street: 'Market', lat: 39.984, lng: -75.343 },
- { name: 'Location B', category: 'House', street: 'Broad', lat: 39.284, lng: -75.833 },
- { name: 'Location C', category: 'Office', street: 'South', lat: 39.123, lng: -74.534 }
- ];
- console.log(GeoJSON.parse(data, {Point: ['lat', 'lng']}));
- /*
- {
- "type": "FeatureCollection",
- "features": [{
- "type": "Feature",
- "geometry": {
- "type": "Point",
- "coordinates": [-75.343, 39.984]
- },
- "properties": {
- "name": "Location A",
- "category": "Store",
- "street": "Market"
- }
- }, {
- "type": "Feature",
- "geometry": {
- "type": "Point",
- "coordinates": [-75.833, 39.284]
- },
- "properties": {
- "name": "Location B",
- "category": "House",
- "street": "Broad"
- }
- }, {
- "type": "Feature",
- "geometry": {
- "type": "Point",
- "coordinates": [-74.534, 39.123]
- },
- "properties": {
- "name": "Location C",
- "category": "Office",
- "street": "South"
- }
- }]
- }
- */
- const data2 = [
- {
- x: 0.5,
- y: 102.0,
- prop0: 'value0'
- },
- {
- line: [[102.0, 0.0], [103.0, 1.0], [104.0, 0.0], [105.0, 1.0]],
- prop0: 'value0',
- prop1: 0.0
- },
- {
- polygon: [
- [ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0] ]
- ],
- prop0: 'value0',
- prop1: {"this": "that"}
- }
- ];
- console.log(GeoJSON.parse(data2, {'Point': ['x', 'y'], 'LineString': 'line', 'Polygon': 'polygon'}));
- /*
- {
- "type": "FeatureCollection",
- "features": [{
- "type": "Feature",
- "geometry": {
- "type": "Point",
- "coordinates": [102, 0.5]
- },
- "properties": {
- "prop0": "value0"
- }
- }, {
- "type": "Feature",
- "geometry": {
- "type": "LineString",
- "coordinates": [
- [102, 0],
- [103, 1],
- [104, 0],
- [105, 1]
- ]
- },
- "properties": {
- "prop0": "value0",
- "prop1": 0
- }
- }, {
- "type": "Feature",
- "geometry": {
- "type": "Polygon",
- "coordinates": [
- [
- [100, 0],
- [101, 0],
- [101, 1],
- [100, 1],
- [100, 0]
- ]
- ]
- },
- "properties": {
- "prop0": "value0",
- "prop1": {
- "this": "that"
- }
- }
- }]
- }
- */
Add Comment
Please, Sign In to add comment