postGIS简单使用

认真看了http://www.cnblogs.com/cnzzb/archive/2009/04/28/1445237.html这篇博客,

主要用到SQL语言:

select myID AS ID,ST_AsText(pt) AS geo from test1;
//以文本格式返回
select *,ST_AsGeoJson(pt) from test1
//以json格式返回
select *,ST_AsGML(pt) from test1
//以gml格式返回

查询Postgresql数据库

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;


public class TestSpringBlob {
	static String url = "jdbc:postgresql://127.0.0.1:5432/myTest";

    static String usr = "postgres";

    static String psd = "ubiloc";

 

    public static void main(String args[]) {

       Connection conn = null;

       try {

           Class.forName("org.postgresql.Driver");

           conn = DriverManager.getConnection(url, usr, psd);

           Statement st = conn.createStatement();

           ResultSet rs = st.executeQuery("select *,ST_AsGML(pt) AS geo from test1");

           while (rs.next()) {
             
              System.out.println(rs.getString("geo"));
              
              System.out.println("---------");
           }

           rs.close();

           st.close();

           conn.close();

       } catch (Exception e) {

           e.printStackTrace();

       }

    }}

输出结果:

<gml:Point><gml:coordinates>0,1</gml:coordinates></gml:Point>
———
<gml:Point><gml:coordinates>0,0</gml:coordinates></gml:Point>
———

转载自:https://blog.csdn.net/cehui115081/article/details/12312147

You may also like...