當前位置: 首頁>>代碼示例>>Java>>正文


Java CRS.parseWKT方法代碼示例

本文整理匯總了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]);
		}
	}
}
 
開發者ID:gama-platform,項目名稱:gama,代碼行數:27,代碼來源:GamaShapeFile.java

示例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);
}
 
開發者ID:gama-platform,項目名稱:gama,代碼行數:23,代碼來源:GamaShapeFile.java

示例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;
}
 
開發者ID:senbox-org,項目名稱:s2tbx,代碼行數:21,代碼來源:GDALProductReader.java

示例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;
}
 
開發者ID:geosolutions-it,項目名稱:soil_sealing,代碼行數:35,代碼來源:UrbanGridProcess.java

示例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;
}
 
開發者ID:TheHortonMachine,項目名稱:hortonmachine,代碼行數:36,代碼來源:CrsUtilities.java

示例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();
	}
}
 
開發者ID:GIScience,項目名稱:openrouteservice,代碼行數:37,代碼來源:GeomUtility.java

示例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();
    }
}
 
開發者ID:IGNF,項目名稱:geoxygene,代碼行數:13,代碼來源:AbstractLayer.java

示例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;
	}
}
 
開發者ID:gama-platform,項目名稱:gama,代碼行數:28,代碼來源:GamaOsmFile.java

示例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.");
    }
 
開發者ID:senbox-org,項目名稱:s2tbx,代碼行數:32,代碼來源:S2tbxReprojectionOp.java

示例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);
    }
}
 
開發者ID:senbox-org,項目名稱:s2tbx,代碼行數:12,代碼來源:S2tbxMosaicFormModel.java

示例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;
}
 
開發者ID:geosolutions-it,項目名稱:soil_sealing,代碼行數:33,代碼來源:UrbanGridProcessTest.java

示例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");
	}
}
 
開發者ID:icholy,項目名稱:geokettle-2.0,代碼行數:20,代碼來源:SRS.java

示例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;
}
 
開發者ID:senbox-org,項目名稱:snap-desktop,代碼行數:11,代碼來源:FeatureLayerType.java

示例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()));
	}
}
 
開發者ID:SiLeBAT,項目名稱:BfROpenLab,代碼行數:8,代碼來源:GisUtils.java

示例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;
}
 
開發者ID:opengeospatial,項目名稱:geopackager,代碼行數:37,代碼來源:ShapefileHarvester.java


注:本文中的org.geotools.referencing.CRS.parseWKT方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。