我想读的大形文件,并试图寻找是否lat和长时间使用geotools坐标
是否有存储形状文件导入到数据库中的任何可能的方式?或者将存储作为以GeoJSON和retirerive更快检查lat和长为坐标?节点JS或Java哪一个会更容易有落实。
您可以为空间数据使用ogr2ogr工具存储形状文件中的MySQL。
阅读此链接:
https://www.igismap.com/insert-shapefile-in-mysql-as-spatial-data/
纠正我,如果我错了,但我的理解是,你有一个Java(春季启动)或后端的NodeJS。
我没有在开发应用程序的NodeJS体验,然而,我有在Java中。我的建议是,你可以实现它非常快速度这样:
所有的一切,我会选择春季启动2个+ JTS和每一个地理空间对象作为几何参数的地图。您可以检查创建地理对象我Gist。决定要使用的SRID。在你的实体,地图地理对象作为Geometry数据类型。检查THW下面的例子:
package model;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import com.vividsolutions.jts.geom.Geometry;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.Singular;
@Entity
@Table(name="stops")
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class Stop implements Serializable {
@Transient private static final long serialVersionUID = -2747601079894033016L;
@Id private String id;
private String codParada;
private String tipoExtraido;
private String uri;
private String titulo;
private Geometry geometria;
private LocalDateTime ultimaActualizacion;
@Singular @ElementCollection private List<String> mensajes;
private String icono;
private String enlace;
private String descripcion;
@Enumerated(EnumType.STRING) private ETipoParada tipo;
}
最简单的方法是使用数据存储打开Shapefile(或以GeoJSON)文件,然后到功能,从该商店复制到PostGIS(或其他Database)数据存储。只需确保在您的Maven POM文件相关模块。
public static void main(String[] args) throws MalformedURLException, IOException {
File inFile = new File("/home/ian/Data/states/states.shp");
Map<String, Object> outParams = new HashMap<>();
outParams.put(PostgisNGDataStoreFactory.DBTYPE.key, PostgisNGDataStoreFactory.DBTYPE.sample);
outParams.put(PostgisNGDataStoreFactory.USER.key, "ian");
outParams.put(PostgisNGDataStoreFactory.PASSWD.key, "ianian");
outParams.put(PostgisNGDataStoreFactory.HOST.key, "localhost");
outParams.put(PostgisNGDataStoreFactory.PORT.key, 5432);
outParams.put(PostgisNGDataStoreFactory.DATABASE.key, "ian");
outParams.put(PostgisNGDataStoreFactory.SCHEMA.key, "public");
// Read
DataStore inputDataStore = DataStoreFinder.getDataStore(
Collections.singletonMap("url", URLs.fileToUrl(inFile)));
String inputTypeName = inputDataStore.getTypeNames()[0];
SimpleFeatureType inputType = inputDataStore.getSchema(inputTypeName);
FeatureSource<SimpleFeatureType, SimpleFeature>
source = inputDataStore.getFeatureSource(inputTypeName);
FeatureCollection<SimpleFeatureType, SimpleFeature>
inputFeatureCollection = source.getFeatures();
DataStore newDataStore = DataStoreFinder.getDataStore(outParams);
String typeName = inputTypeName;
newDataStore.createSchema(inputType);
SimpleFeatureStore featureStore = (SimpleFeatureStore) newDataStore.getFeatureSource(typeName);
/*
* //Optional Filter block //filter String geometryPropertyName =
* inputType.getGeometryDescriptor().getLocalName();
* CoordinateReferenceSystem targetCRS =
* inputType.getGeometryDescriptor().getCoordinateReferenceSystem();
*
* double x1 = 11.5; double y1 = 49.8; double x2 = 12.0; double y2 = 50.1;
*
* ReferencedEnvelope bbox = new ReferencedEnvelope(x1, y1, x2, y2,
* targetCRS); FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2();
* Filter filter = ff.bbox(ff.property(geometryPropertyName), bbox);
*/
// write results
featureStore.addFeatures(source.getFeatures(/*filter*/));
//tidy up
inputDataStore.dispose();
newDataStore.dispose();
newDataStore.createSchema(inputType);
String typeName1 = newDataStore.getTypeNames()[0];
SimpleFeatureStore featureStore1 = (SimpleFeatureStore) newDataStore.getFeatureSource(typeName1);
featureStore1.addFeatures(inputFeatureCollection);
inputDataStore.dispose();
newDataStore.dispose();
}