如何使用 GeoTools/ProJ.4(或其他 api)将坐标从 HK80 GRID 转换为纬度/经度?

发布于 2024-12-23 00:39:14 字数 105 浏览 2 评论 0原文

如何将一组 hk80 网格转换为纬度/经度?

HK 1980 网格是 EPSG 2326,而纬度/经度 WGS84 是 EPSG 4326

或者是否有更适合这样做

how to convert a set of hk80 grid to lat/lon?

HK 1980 Grid is EPSG 2326, while Lat/Long WGS84 is EPSG 4326

Or is there any is more suitible for doing this

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

生寂 2024-12-30 00:39:14

我希望下面的代码可以帮助你。我需要使用 GeoTools 来实现你的目的。另外,您需要为 epsg 2326 插入相关的北距和东距。但是,我仍然无法解决异常问题。为了正确使用此代码,您需要下载并导入除 gt-epsg-postgresql 之外的所有 GeoTools jar。

package org.geotools.tutorial;

import java.awt.geom.Point2D;
import java.io.File;

import org.geotools.data.FileDataStore;
import org.geotools.data.FileDataStoreFinder;
import org.geotools.data.simple.SimpleFeatureSource;
import org.geotools.factory.Hints;
import org.geotools.map.FeatureLayer;
import org.geotools.map.Layer;
import org.geotools.map.MapContent;
import org.geotools.referencing.CRS;
import org.geotools.referencing.ReferencingFactoryFinder;
import org.geotools.styling.SLD;
import org.geotools.styling.Style;
import org.geotools.swing.JMapFrame;
import org.geotools.swing.data.JFileDataStoreChooser;
import org.opengis.referencing.crs.CRSAuthorityFactory;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
import org.opengis.referencing.operation.MathTransform;
import org.geotools.referencing.*;
/**
 * Prompts the user for a shapefile and displays the contents on the screen in a map frame.
 * <p>
 * This is the GeoTools Quickstart application used in documentationa and tutorials. *
 */
public class quickstart {

/**
 * GeoTools Quickstart demo application. Prompts the user for a shapefile and displays its
 * contents on the screen in a map frame
 */
    public static void main(String[] args) throws Exception {
        //Point2D.Double srcProjec = new Point2D.Double (836694.050, 819069.800);
        //Point2D.Double dstProjec = new Point2D.Double (132,37);
        // display a data store file chooser dialog for shapefiles
        //Hints hints = new Hints(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER, Boolean.TRUE);
        //CRSAuthorityFactory factory = ReferencingFactoryFinder.getCRSAuthorityFactory("EPSG", hints);
        //CoordinateReferenceSystem crs = factory.createCoordinateReferenceSystem("EPSG:4326");
        CRSAuthorityFactory   factory = CRS.getAuthorityFactory(true);
        CoordinateReferenceSystem srcCRS = factory.createCoordinateReferenceSystem("EPSG:2326");
        CoordinateReferenceSystem dstCRS = factory.createCoordinateReferenceSystem("EPSG:4326");
        boolean lenient = true; // allow for some error due to different datums
        MathTransform transform = CRS.findMathTransform(srcCRS, dstCRS, lenient);
        double[] srcProjec = {818039, 836361};// easting, northing, 
        double[] dstProjec = {0, 0};
        transform.transform(srcProjec, 0, dstProjec, 0, 1);
        System.out.println("longitude: " + dstProjec[0] + ", latitude: " + dstProjec[1]);

    }

}

I hope that the following code can help you. I need to use GeoTools to achieve your purpose. Also, you need to insert the relevant northing and easting for epsg 2326. However, I still cannot solve the exception problem yet. In order to use this code properly, you need to download and import all GeoTools jars besides gt-epsg-postgresql.

package org.geotools.tutorial;

import java.awt.geom.Point2D;
import java.io.File;

import org.geotools.data.FileDataStore;
import org.geotools.data.FileDataStoreFinder;
import org.geotools.data.simple.SimpleFeatureSource;
import org.geotools.factory.Hints;
import org.geotools.map.FeatureLayer;
import org.geotools.map.Layer;
import org.geotools.map.MapContent;
import org.geotools.referencing.CRS;
import org.geotools.referencing.ReferencingFactoryFinder;
import org.geotools.styling.SLD;
import org.geotools.styling.Style;
import org.geotools.swing.JMapFrame;
import org.geotools.swing.data.JFileDataStoreChooser;
import org.opengis.referencing.crs.CRSAuthorityFactory;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
import org.opengis.referencing.operation.MathTransform;
import org.geotools.referencing.*;
/**
 * Prompts the user for a shapefile and displays the contents on the screen in a map frame.
 * <p>
 * This is the GeoTools Quickstart application used in documentationa and tutorials. *
 */
public class quickstart {

/**
 * GeoTools Quickstart demo application. Prompts the user for a shapefile and displays its
 * contents on the screen in a map frame
 */
    public static void main(String[] args) throws Exception {
        //Point2D.Double srcProjec = new Point2D.Double (836694.050, 819069.800);
        //Point2D.Double dstProjec = new Point2D.Double (132,37);
        // display a data store file chooser dialog for shapefiles
        //Hints hints = new Hints(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER, Boolean.TRUE);
        //CRSAuthorityFactory factory = ReferencingFactoryFinder.getCRSAuthorityFactory("EPSG", hints);
        //CoordinateReferenceSystem crs = factory.createCoordinateReferenceSystem("EPSG:4326");
        CRSAuthorityFactory   factory = CRS.getAuthorityFactory(true);
        CoordinateReferenceSystem srcCRS = factory.createCoordinateReferenceSystem("EPSG:2326");
        CoordinateReferenceSystem dstCRS = factory.createCoordinateReferenceSystem("EPSG:4326");
        boolean lenient = true; // allow for some error due to different datums
        MathTransform transform = CRS.findMathTransform(srcCRS, dstCRS, lenient);
        double[] srcProjec = {818039, 836361};// easting, northing, 
        double[] dstProjec = {0, 0};
        transform.transform(srcProjec, 0, dstProjec, 0, 1);
        System.out.println("longitude: " + dstProjec[0] + ", latitude: " + dstProjec[1]);

    }

}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文