GithubHelp home page GithubHelp logo

suretarget / shp2geojson.js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from gipong/shp2geojson.js

0.0 0.0 0.0 3.22 MB

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.

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

License: MIT License

JavaScript 97.25% HTML 2.75%

shp2geojson.js's Introduction

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.

shp2geojson.js's People

Contributors

gipong avatar eblondel avatar u10313335 avatar vharmain avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.