本文整理汇总了Java中org.geotools.referencing.CRS.parseWKT方法的典型用法代码示例。如果您正苦于以下问题:Java CRS.parseWKT方法的具体用法?Java CRS.parseWKT怎么用?Java CRS.parseWKT使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.geotools.referencing.CRS
的用法示例。
在下文中一共展示了CRS.parseWKT方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: ShapeInfo
import org.geotools.referencing.CRS; //导入方法依赖的package包/类
public ShapeInfo(final String propertiesString) {
super(propertiesString);
final String[] segments = split(propertiesString);
itemNumber = Integer.valueOf(segments[1]);
final String crsString = segments[2];
CoordinateReferenceSystem theCRS;
if ("null".equals(crsString) || crsString.startsWith("Unknown")) {
theCRS = null;
} else {
try {
theCRS = CRS.parseWKT(crsString);
} catch (final Exception e) {
theCRS = null;
}
}
crs = theCRS;
width = Double.valueOf(segments[3]);
height = Double.valueOf(segments[4]);
if (segments.length > 5) {
final String[] names = splitByWholeSeparatorPreserveAllTokens(segments[5], SUB_DELIMITER);
final String[] types = splitByWholeSeparatorPreserveAllTokens(segments[6], SUB_DELIMITER);
for (int i = 0; i < names.length; i++) {
attributes.put(names[i], types[i]);
}
}
}
示例2: toPropertyString
import org.geotools.referencing.CRS; //导入方法依赖的package包/类
@Override
public String toPropertyString() {
// See Issue #1603: .toWKT() && pa can sometimes cause problem with
// certain projections.
String system = crs == null ? "Unknown projection" : crs.toWKT();
try {
CRS.parseWKT(system);
} catch (final Exception e) {
// The toWKT()/parseWKT() pair has a problem
String srs = CRS.toSRS(crs);
if (srs == null && crs != null) {
srs = crs.getName().getCode();
}
system = "Unknown projection " + srs;
}
final String attributeNames = join(attributes.keySet(), SUB_DELIMITER);
final String types = join(attributes.values(), SUB_DELIMITER);
final Object[] toSave =
new Object[] { super.toPropertyString(), itemNumber, system, width, height, attributeNames, types };
return join(toSave, DELIMITER);
}
示例3: buildGeoCoding
import org.geotools.referencing.CRS; //导入方法依赖的package包/类
private static GeoCoding buildGeoCoding(Dataset gdalProduct) {
String wellKnownText = gdalProduct.GetProjectionRef();
if (!StringUtils.isNullOrEmpty(wellKnownText)) {
int imageWidth = gdalProduct.getRasterXSize();
int imageHeight = gdalProduct.getRasterYSize();
double[] adfGeoTransform = new double[6];
gdalProduct.GetGeoTransform(adfGeoTransform);
double originX = adfGeoTransform[0];
double originY = adfGeoTransform[3];
double pixelSizeX = adfGeoTransform[1];
double pixelSizeY = (adfGeoTransform[5] > 0) ? adfGeoTransform[5] : -adfGeoTransform[5];
try {
CoordinateReferenceSystem crs = CRS.parseWKT(wellKnownText);
return new CrsGeoCoding(crs, imageWidth, imageHeight, originX, originY, pixelSizeX, pixelSizeY);
} catch (Exception ex) {
logger.log(Level.SEVERE, ex.getMessage(), ex);
}
}
return null;
}
示例4: reprojectToEqualArea
import org.geotools.referencing.CRS; //导入方法依赖的package包/类
/**
* Private method which reprojects the input Geometry in the input CRS to a Lambert-Equal Area CRS used for calculating Geometry Area and
* perimeter.
*
* @param sourceCRS Source geometry CRS.
* @param sourceGeometry Source Geometry
* @return
* @throws FactoryException
* @throws TransformException
*/
private Geometry reprojectToEqualArea(CoordinateReferenceSystem sourceCRS,
Geometry sourceGeometry) throws FactoryException, TransformException {
// Reproject to the Lambert Equal Area
// Geometry center used for centering the reprojection on the Geometry(reduces distance artifacts)
Point center = sourceGeometry.getCentroid();
// Creation of the MathTransform associated to the reprojection
MathTransform transPoint = CRS.findMathTransform(sourceCRS, WGS84, true);
Point centerRP = (Point) JTS.transform(center, transPoint);
// Creation of a wkt for the selected Geometry
String wkt = PROJ_4326.replace("%LAT0%", String.valueOf(centerRP.getY()));
wkt = wkt.replace("%LON0%", String.valueOf(centerRP.getX()));
// Parsing of the selected WKT
final CoordinateReferenceSystem targetCRS = CRS.parseWKT(wkt);
// Creation of the MathTransform associated to the reprojection
MathTransform trans = CRS.findMathTransform(sourceCRS, targetCRS);
// Geometry reprojection
Geometry geoPrj;
if (!trans.isIdentity()) {
geoPrj = JTS.transform(sourceGeometry, trans);
} else {
geoPrj = sourceGeometry;
}
return geoPrj;
}
示例5: readProjectionFile
import org.geotools.referencing.CRS; //导入方法依赖的package包/类
/**
* Reads a {@link CoordinateReferenceSystem} from a prj file.
*
* @param filePath the path to the prj file or the connected datafile it sidecar file for.
* @param extension the extension of the data file. If <code>null</code> it is assumed to be prj.
*
* @return the read {@link CoordinateReferenceSystem}.
*
* @throws Exception
*/
@SuppressWarnings("nls")
public static CoordinateReferenceSystem readProjectionFile( String filePath, String extension ) throws Exception {
CoordinateReferenceSystem crs = null;
String prjPath = null;
String filePathLower = filePath.trim().toLowerCase();
if (filePathLower.endsWith(".prj")) {
// it is the prj file
prjPath = filePath;
} else if (extension != null && filePathLower.endsWith("." + extension)) {
// datafile was supplied (substitute extension)
int dotLoc = filePath.lastIndexOf(".");
prjPath = filePath.substring(0, dotLoc);
prjPath = prjPath + ".prj";
} else {
prjPath = filePath + ".prj";
}
File prjFile = new File(prjPath);
if (!prjFile.exists()) {
throw new ModelsIOException("The prj file doesn't exist: " + prjPath, "CRSUTILITIES");
}
String wkt = FileUtilities.readFile(prjFile);
crs = CRS.parseWKT(wkt);
return crs;
}
示例6: getArea
import org.geotools.referencing.CRS; //导入方法依赖的package包/类
public static double getArea(Geometry geom, Boolean inMeters) throws Exception
{
if (inMeters) {
if (geom instanceof Polygon)
{
Polygon poly = (Polygon) geom;
double area = Math.abs(getSignedArea(poly.getExteriorRing().getCoordinateSequence()));
for (int i = 0; i < poly.getNumInteriorRing(); i++) {
LineString hole = poly.getInteriorRingN(i);
area -= Math.abs(getSignedArea(hole.getCoordinateSequence()));
}
return area;
}
else if (geom instanceof LineString)
{
LineString ring = (LineString)geom;
return getSignedArea(ring.getCoordinateSequence());
}
else
{
if (TRANSFORM_WGS84_SPHERICALMERCATOR == null) {
String wkt = "PROJCS[\"WGS 84 / Pseudo-Mercator\",GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563,AUTHORITY[\"EPSG\",\"7030\"]],AUTHORITY[\"EPSG\",\"6326\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4326\"]],PROJECTION[\"Mercator_1SP\"],PARAMETER[\"central_meridian\",0],PARAMETER[\"scale_factor\",1],PARAMETER[\"false_easting\",0],PARAMETER[\"false_northing\",0],UNIT[\"metre\",1,AUTHORITY[\"EPSG\",\"9001\"]],AXIS[\"X\",EAST],AXIS[\"Y\",NORTH],AUTHORITY[\"EPSG\",\"3857\"]]";
CoordinateReferenceSystem crs = CRS.parseWKT(wkt);// CRS.decode("EPSG:3857");
TRANSFORM_WGS84_SPHERICALMERCATOR = CRS.findMathTransform(DefaultGeographicCRS.WGS84, crs, true);
}
Geometry transformedGeometry = JTS.transform(geom, TRANSFORM_WGS84_SPHERICALMERCATOR);
return transformedGeometry.getArea();
}
} else {
return geom.getArea();
}
}
示例7: setCRSFromWKTString
import org.geotools.referencing.CRS; //导入方法依赖的package包/类
/**
* Crée un CRS a partir d'un crs sous forme de chaine de caractère WKT.
*
* @param scrs
*/
public void setCRSFromWKTString(String scrs) {
try {
this.ftscrs = CRS.parseWKT(scrs);
} catch (Exception e) {
e.printStackTrace();
}
}
示例8: OSMInfo
import org.geotools.referencing.CRS; //导入方法依赖的package包/类
public OSMInfo(final String propertiesString) throws NoSuchAuthorityCodeException, FactoryException {
super(propertiesString);
if (!hasFailed) {
final String[] segments = split(propertiesString);
itemNumber = Integer.valueOf(segments[1]);
final String crsString = segments[2];
if ("null".equals(crsString)) {
crs = null;
} else {
crs = CRS.parseWKT(crsString);
}
width = Double.valueOf(segments[3]);
height = Double.valueOf(segments[4]);
if (segments.length > 5) {
final String[] names = splitByWholeSeparatorPreserveAllTokens(segments[5], SUB_DELIMITER);
final String[] types = splitByWholeSeparatorPreserveAllTokens(segments[6], SUB_DELIMITER);
for (int i = 0; i < names.length; i++) {
attributes.put(names[i], types[i]);
}
}
} else {
itemNumber = 0;
width = 0.0;
height = 0.0;
crs = null;
}
}
示例9: createTargetCRS
import org.geotools.referencing.CRS; //导入方法依赖的package包/类
private CoordinateReferenceSystem createTargetCRS(GeoPos centerGeoPos) throws OperatorException {
try {
if (wktFile != null) {
return CRS.parseWKT(FileUtils.readText(wktFile));
}
if (crs != null) {
try {
return CRS.parseWKT(crs);
} catch (FactoryException ignored) {
// prefix with EPSG, if there are only numbers
if (crs.matches("[0-9]*")) {
crs = "EPSG:" + crs;
}
// append center coordinates for AUTO code
if (crs.matches("AUTO:[0-9]*")) {
// final GeoPos centerGeoPos = ProductUtils.getCenterGeoPos(sourceProduct);
crs = String.format("%s,%s,%s", crs, centerGeoPos.lon, centerGeoPos.lat);
}
// force longitude==x-axis and latitude==y-axis
return CRS.decode(crs, true);
}
}
if (collocationProduct != null && collocationProduct.getSceneGeoCoding() != null) {
return collocationProduct.getSceneGeoCoding().getMapCRS();
}
} catch (FactoryException | IOException e) {
throw new OperatorException(String.format("Target CRS could not be created: %s", e.getMessage()), e);
}
throw new OperatorException("Target CRS could not be created.");
}
示例10: getTargetCRS
import org.geotools.referencing.CRS; //导入方法依赖的package包/类
CoordinateReferenceSystem getTargetCRS() throws FactoryException {
final String crs = (String) getPropertyValue("crs");
if (crs == null) {
return null;
}
try {
return CRS.parseWKT(crs);
} catch (FactoryException ignored) {
return CRS.decode(crs, true);
}
}
示例11: reprojectToEqualArea
import org.geotools.referencing.CRS; //导入方法依赖的package包/类
private static Geometry reprojectToEqualArea(CoordinateReferenceSystem sourceCRS,
Geometry sourceGeometry) throws FactoryException, TransformException {
// Reproject to the Lambert Equal Area
final ReferencedEnvelope env = new ReferencedEnvelope(sourceGeometry.getEnvelopeInternal(),
sourceCRS);
// Geometry center used for centering the reprojection on the Geometry(reduces distance artifacts)
double lat = env.getMedian(1);
double lon = env.getMedian(0);
// Geometry center used for centering the reprojection on the Geometry(reduces distance artifacts)
Point center = sourceGeometry.getCentroid();
// Creation of the MathTransform associated to the reprojection
MathTransform transPoint = CRS.findMathTransform(sourceCRS, CRS.decode("EPSG:4326"), true);
Point centerRP = (Point) JTS.transform(center, transPoint);
lon = centerRP.getY();
lat = centerRP.getX();
// Creation of a wkt for the selected Geometry
String wkt = UrbanGridProcess.PROJ_4326.replace("%LAT0%", String.valueOf(lat));
wkt = wkt.replace("%LON0%", String.valueOf(lon));
// Parsing of the selected WKT
final CoordinateReferenceSystem targetCRS = CRS.parseWKT(wkt);
// Creation of the MathTransform associated to the reprojection
MathTransform trans = CRS.findMathTransform(sourceCRS, targetCRS, true);
// Geometry reprojection
Geometry geoPrj;
if (!trans.isIdentity()) {
geoPrj = JTS.transform(sourceGeometry, trans);
} else {
geoPrj = sourceGeometry;
}
return geoPrj;
}
示例12: createCRSFromWKT
import org.geotools.referencing.CRS; //导入方法依赖的package包/类
/**
* Creates a {@link CoordinateReferenceSystem} instance from a WKT string.
* (helper method)
*
* @param wkt The WKT string.
* @return The appropriate {@link CoordinateReferenceSystem} instance.
* @throws KettleStepException
*/
private static CoordinateReferenceSystem createCRSFromWKT(String wkt) throws KettleStepException {
Parser wktParser = new Parser();
Preprocessor preproc = new Preprocessor(wktParser);
try {
preproc.parseObject(wkt, CoordinateReferenceSystem.class);
return CRS.parseWKT(wkt);
} catch (Exception e) {
throw new KettleStepException("Could not create a SRS metadata according to " +
"the delivered WKT representation of the spatial reference system");
}
}
示例13: convertDomToValue
import org.geotools.referencing.CRS; //导入方法依赖的package包/类
@Override
public Object convertDomToValue(DomElement parentElement, Object value) throws ConversionException,
ValidationException {
try {
value = CRS.parseWKT(parentElement.getValue());
} catch (FactoryException e) {
throw new IllegalArgumentException(e);
}
return value;
}
示例14: getCoordinateSystem
import org.geotools.referencing.CRS; //导入方法依赖的package包/类
public static CoordinateReferenceSystem getCoordinateSystem(String shpFile)
throws InvalidPathException, MalformedURLException, IOException, FactoryException, NoSuchFileException {
try (Stream<String> stream = Files
.lines(KnimeUtils.getFile(FilenameUtils.removeExtension(shpFile) + ".prj").toPath())) {
return CRS.parseWKT(stream.collect(Collectors.joining()));
}
}
示例15: inferCRSFromPrjFile
import org.geotools.referencing.CRS; //导入方法依赖的package包/类
private String inferCRSFromPrjFile(String url) {
if (url.endsWith(".shp")) {
url = url.substring(0, url.length() - 4);
}
url += ".prj";
StringBuilder buf = new StringBuilder();
InputStream is = null;
CoordinateReferenceSystem crs;
try {
is = new URL(url).openStream();
Reader r = new InputStreamReader(is, Charset.forName("ISO-8859-1"));
char[] line = new char[1024];
int n;
while ((n = r.read(line)) > 0) {
buf.append(line, 0, n);
}
crs = CRS.parseWKT(buf.toString());
} catch (Exception e) {
if (is != null) {
try { is.close(); } catch (IOException e1) {}
}
return null; // can't determine CRS
}
String srid = CRS.toSRS(crs);
if (srid.endsWith("WGS_1984")) {
srid = "4326";
}
if (srid.startsWith("EPSG:")) {
srid = srid.substring(5);
}
return srid;
}