有没有机会改变geojson的投影(mapshaper)

问题描述 投票:0回答:1
  • 大家好,
  • 我正在使用OpenLayers 5,Angular 6,mapshaper工具(将shp转换为json)。
  • MapshaperToolGit Code

我的过程

  • 我已经安装了npm mapshaper --save
  • 我能够上传不同的.shp文件,并能够获取json功能数据。
  • 我有2个不同的.shp文件[layer-ind.shp,layer-administration.shp]
  • layer-ind.shp文件上传了它的json给出的样子

{ "type": "FeatureCollection", "features": [ { "type": "Feature", "properties": {}, "geometry": { "type": "LineString", "coordinates": [ [ 75.89355468749999, 18.521283325496277 ], [ 80.6396484375, 19.68397023588844 ] ] } } ] }

  • layer-us.shp文件上传了它的json给出的样子

{ "type": "FeatureCollection", "features": [ { "type":"Feature", "geometry":{ "type":"LineString", "coordinates":[ [-349771.1875,445307.8125], [-349789.6875,445314.375], [-349796.5625,445321.5625], [-349792.78119999915,445341.4375], [-349786.53119999915,445351.71880000085], [-349771.1875,445307.8125]]}, "properties":{ "TYPE":"ISLAND","RuleID":3, "Shape_Leng":544.475438955 } } ] }

在地图上预览这两个图层(要素)预览时1. layer-ind.json文件会给出正确的结果,并且能够在正确的位置看到地图上的图层2. layer-us.json文件在地图上显示错误的位置(0,0)

  • 如何解决这些第二点层-us.json问题,我也改变了重新投影的方式

const vectorSource = new VectorSource({ features: (new GeoJSON()).readFeatures(geojson, { featureProjection: 'EPSG:4326' }); });

  • 我也更改了featureProjection代码,但它不工作的图层-us.json。
  • 请帮忙
  • 救我的日子
openlayers geojson projection map-projections mapshaper
1个回答
0
投票

您需要指定数据投影和特征投影。 featurePprojection是地图视图的投影。 dataProjection是json中坐标的投影。我可以看到layer-ind的dataProjection是'EPSG:4326',layer-us的dataProjection似乎使用了局部投影的坐标。你知道哪个投影或岛屿在哪里?

const vectorSource = new VectorSource({
        features: (new GeoJSON()).readFeatures(geojson, {
        dataProjection: 'xxxx',
        featureProjection: 'yyyy'
      })
    });

基于投影定义,您现在在这里给出了一个工作示例(在这里运行它使用完整的构建语法)

proj4.defs('NAD_1983_California_Teale_Albers', 'PROJCS["NAD_1983_California_Teale_Albers",GEOGCS["GCS_North_American_1983",DATUM["D_North_American_1983",SPHEROID["GRS_1980",6378137.0,298.257222101]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Albers"],PARAMETER["False_Easting",0.0],PARAMETER["False_Northing",-4000000.0],PARAMETER["Central_Meridian",-120.0],PARAMETER["Standard_Parallel_1",34.0],PARAMETER["Standard_Parallel_2",40.5],PARAMETER["Latitude_Of_Origin",0.0],UNIT["Meter",1.0]]');

ol.proj.proj4.register(proj4);

geojson = {
  "type": "FeatureCollection",
  "features": [
{
  "type":"Feature",
  "geometry":{
    "type":"LineString",
    "coordinates":[
      [-349771.1875,445307.8125],
      [-349789.6875,445314.375],
      [-349796.5625,445321.5625],
      [-349792.78119999915,445341.4375],
      [-349786.53119999915,445351.71880000085],
      [-349771.1875,445307.8125]]},
  "properties":{
    "TYPE":"ISLAND","RuleID":3,
    "Shape_Leng":544.475438955
  }
}
  ]
}

var map = new ol.Map({
  layers: [ new ol.layer.Tile({ source: new ol.source.OSM() }) ],
  target: 'map',
  view: new ol.View()
});


const vectorSource = new ol.source.Vector({
    features: (new ol.format.GeoJSON()).readFeatures(geojson, {
    dataProjection: 'NAD_1983_California_Teale_Albers',
    featureProjection: map.getView().getProjection()
  })
});


map.addLayer(new ol.layer.Vector({source: vectorSource}));

map.getView().fit(vectorSource.getExtent());
<link href="https://cdn.rawgit.com/openlayers/openlayers.github.io/master/en/v5.3.0/css/ol.css" rel="stylesheet" />
<script src="https://cdn.rawgit.com/openlayers/openlayers.github.io/master/en/v5.3.0/build/ol.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/proj4js/2.5.0/proj4.js"></script>

<div id="map" class="map"></div>
© www.soinside.com 2019 - 2024. All rights reserved.