• Stars
    star
    261
  • Rank 156,630 (Top 4 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created almost 10 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Convert shapefile to geoJSON via a web browser without Server-Side code. This conversion will unzip your file and reproject the data with correct encoding in JavaScript.

shp2geojson.js

Convert shapefile to geoJSON via a web browser without Server-Side code. This conversion will unzip your file and reproject the data with correct encoding in JavaScript.

Inspired by this project by wavded http://github.com/wavded/js-shapefile-to-geojson

Usage

Include all of the necessary files for the webpage to preview shp.

<script src="https://cdnjs.cloudflare.com/ajax/libs/proj4js/2.3.3/proj4.js"></script>
<script src="lib/jszip.js"></script>
<script src="lib/jszip-utils.js"></script>
<!--[if IE]>
<script type="text/javascript" src="lib/jszip-utils-ie.js"></script>
<![endif]-->

<script src="preprocess.js"></script>
<script src="preview.js"></script>

Load the ZIP archive that must contain the .shp and .dbf files and replace the .prj file of shapefile with EPSG code.

Two options available if you need to set the EPSG or encoding for best fit to your data. You can skip EPSG code field if your ZIP archive contain the .prj file.

loadshp({
    url: '/shp/test.zip', // path or your upload file
    encoding: 'big5' // default utf-8
    EPSG: 3826 // default 4326
}, function(geojson) {
    // geojson returned
});

Use with Leaflet.js

var map = L.map('map').setView([ 0, 0 ], 10),
vector = L.geoJson().addTo(map);

L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png' , { maxZoom: 18}).addTo(map);

loadshp({
    url: '/shp/test.zip',
    encoding: 'big5',
    EPSG: 3826
}, function(data) {
    vector.addData(data);
    map.fitBounds(vector.getBounds()); 
});

Use with Google Maps API v3

var map = new google.maps.Map(document.getElementById('map'), {
    zoom: 10,
    center: {lat: 0, lng: 0}
});

loadshp({
    url: '/shp/test.zip',
    encoding: 'big5',
    EPSG: 3826
}, function(data) {
    var bounds = new google.maps.LatLngBounds(),
    bbox = data.bbox;
    
    map.data.addGeoJson(data);
    bounds.extend(new google.maps.LatLng (bbox[1], bbox[0]));
    bounds.extend(new google.maps.LatLng (bbox[3], bbox[2]))
    map.fitBounds(bounds);
});

Demo

http://gipong.github.io/shp2geojson.js/

index

Case 1 (Encoding: Big5)

Big5

Case 2 (Encoding: Shift_JIS)

Shift_JIS

License

The MIT License (MIT)

Copyright (c) 2015 Gipong

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

More Repositories

1

grafana-groupedbarchart-panel

grouped bar chart panel plugin for grafana
JavaScript
71
star
2

automatic-metro-map

Automatic generate a schematic map by using non-linear optimization with some constraints
JavaScript
17
star
3

view-georeferenced-jpg

View geo-referenced jpeg on web
JavaScript
7
star
4

crawler-celery-redis

Dockerize crawler application, Celery and Redis with docker-compose
Python
4
star
5

compare2shp

Compares two shapefile and visualizes the comparison results. This comparison tool can highlight differences with geometry.
JavaScript
4
star
6

WIR_hw2

Pagerank, simrank, hits
PHP
2
star
7

dockerize-instagram-clone

JavaScript
2
star
8

WIR_hw1

PHP
1
star
9

Paint_demo

Java
1
star
10

DB_prj

C++
1
star
11

tgslab-pages

Taiwan Geospatial Open Source Lab page
HTML
1
star
12

sigspatial2016-demopaper

We look into issues in organizing large sets of travel photos, and propose methods for helping people recollect their journey.
CSS
1
star
13

Mapbasic

1
star
14

geopandas-intro

geopandas intro
Jupyter Notebook
1
star
15

movementtypes

extract GPS traces from file and analyze them to reveal movement types
Python
1
star
16

coordsolverjs

provide an easy way for setting parameters in numeric function
JavaScript
1
star
17

100NT-demo

Build AR demo with Vuforia and Unity
ASP
1
star
18

crawler-in-k8s

JavaScript
1
star
19

roadkill_data_visualization

roadkill_data_visualization
Jupyter Notebook
1
star
20

csie_sumo

PHP
1
star
21

pywpsprj

JavaScript
1
star
22

roadkill-visualization

This set of slides is an introduction to geospatial data visualization with roadkill data
HTML
1
star
23

link-folder

Creating a shortcut to a folder with Electron
HTML
1
star
24

printHexagon

Allow dynamically changing the side length and fill a page with the hexagons on A4. It's also provide an option to colorize hexagons with random color.
JavaScript
1
star
25

ckanschema-json-to-docs

JavaScript
1
star