Comments (4)
I might not be able to help with this... but can you tell me what part of mapshaper you want to use? Do you want to use any parts of the graphics user interface, or just some of the geoprocessing functions?
from mapshaper.
I have a array like this:
// x means lng, y means lat
const mydata = [{ x: 0, y: 0, value: 0}, { x: 1, y: 1, value: 1}, ...]
I want to turn it into geojson format:
{
"type":"FeatureCollection",
"features": [
{
"type":"Feature",
"geometry":{"type":"Point", "coordinates":[0, 0]},
"properties": {value: 0}
},
...
]
}
I have read some source code, it use importJSONTable(content, opts);
.
How can I pass opts to importJSONTable
function to transfer mydata to geojson?
from mapshaper.
importJSONTable()
is an internal function that is not designed to be called directly. I would recommend using the API function applyCommands()
(see https://github.com/mbloch/mapshaper/wiki/Using-mapshaper-programmatically#applycommands).
Your code would look something like this:
var cmd = "-i data.json -points x=x y=y -o format=geojson"
var output = await mapshaper.applyCommands(cmd, mydata);
var data = JSON.parse(output["data.json"]);
You can verify that the above command is correct using the mapshaper command line tool or the console in the web UI.
from mapshaper.
You can also create your own function for the purpose, not attached to mapshaper library in particular
const mydata = [{ x: 0, y: 0, value: 0}, { x: 1, y: 1, value: 1}]
const generateGeoJSONFromArray = data => {
return {
"type":"FeatureCollection",
"features": data.map(el => {
const {x, y, ...properties} = el;
return {
"type":"Feature",
"geometry":{
"type":"Point",
"coordinates":[x, y]
},
"properties": properties
}
})
}
}
console.log(generateGeoJSONFromArray(mydata))
from mapshaper.
Related Issues (20)
- light blue paths and performance HOT 3
- Memory usage almost 4x size of input geojson file HOT 4
- Filter lines still create polygons HOT 5
- When hovering mouse over feature and scrolling, fill color freaks out HOT 1
- Point layers and data layers do not show up HOT 2
- Cannot convert between WGS84 and Webmercator after converting and saving data as EPSG:3857. HOT 3
- Error on simplifying GeoJSON file HOT 11
- Javascript error related to polygon editing causes GUI to crash HOT 1
- There is an issue when you import a shapefile HOT 2
- Clip command removes Features visually but not from exported file. HOT 4
- Sticky hand HOT 1
- snap effects multiples layers HOT 1
- geojson from points HOT 2
- Export failed Export failed for an unknown reason HOT 3
- topojson files in power bi HOT 2
- Problem in drawing polygon and importing snapshot file HOT 4
- Export to Shape File Not working HOT 12
- Bug: can't open snapshot file I created on mapshaper.org HOT 3
- Bug: copy as GeoJSON doesn't copy GeoJSON HOT 1
- filter-slivers remove-empty bug
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mapshaper.