c# 操作postgis

10 篇文章 0 订阅

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;using System.Drawing;

using System.Linq;using System.Text;

using System.Windows.Forms;using Npgsql;
namespace org.lreis.grid

{    

public partial class Form2 : Form    {    

   private DataSet ds = new DataSet();    

    private DataTable dt = new DataTable();   

     private string sql = "SELECT asewkt(the_geom) FROM florida_polygon";      

  public Form2()        {       

     InitializeComponent();     

   }
        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)        {   

         try            {            

    // PostgeSQL-style connection string        

        string connstring = String.Format("Server={0};Port={1};" +                

    "User Id={2};Password={3};Database={4};",                   

 tbHost.Text, tbPort.Text, tbUser.Text,             

       tbPass.Text, tbDataBaseName.Text);              

  // Making connection with Npgsql provider           

     NpgsqlConnection conn = new NpgsqlConnection(connstring);   

             conn.Open();             

   // quite complex sql statement                  

              // data adapter making request from our connection          

      NpgsqlDataAdapter da = new NpgsqlDataAdapter(sql, conn);     

           // i always reset DataSet before i do            

    // something with it.... i don't know why :-)        

        ds.Reset();              

  // filling DataSet with result from NpgsqlDataAdapter        

        da.Fill(ds);           

     // since it C# DataSet can handle multiple tables, we will select first           

     dt = ds.Tables[0];           

     // connect grid to DataTable        

        dataGridView1.DataSource = dt;       

         // since we only showing the result we don't need connection anymore       

         conn.Close();     

       }       

     catch (Exception msg)       

     {                // something went wrong, and you wanna know why               

 MessageBox.Show(msg.ToString());             

   throw;            }        }
                    }}

"SELECT asewkt(the_geom) FROM florida_polygon";查询几何数据。

重点是引用Npgsql.dll,下载地址http://pgfoundry.org/frs/?group_id=1000140

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Create and manage spatial data with PostGIS Key Features Import and export geographic data from the PostGIS database using the available tools Maintain, optimize, and fine-tune spatial data for long-term viability Utilize the parallel support functionality that was introduced in PostgreSQL 9.6 Book Description PostGIS is a spatial database that integrates the advanced storage and analysis of vector and raster data, and is remarkably flexible and powerful. PostGIS provides support for geographic objects to the PostgreSQL object-relational database and is currently the most popular open source spatial databases. If you want to explore the complete range of PostGIS techniques and expose related extensions, then this book is for you. This book is a comprehensive guide to PostGIS tools and concepts which are required to manage, manipulate, and analyze spatial data in PostGIS. It covers key spatial data manipulation tasks, explaining not only how each task is performed, but also why. It provides practical guidance allowing you to safely take advantage of the advanced technology in PostGIS in order to simplify your spatial database administration tasks. Furthermore, you will learn to take advantage of basic and advanced vector, raster, and routing approaches along with the concepts of data maintenance, optimization, and performance, and will help you to integrate these into a large ecosystem of desktop and web tools. By the end, you will be armed with all the tools and instructions you need to both manage the spatial database system and make better decisions as your project's requirements evolve. What you will learn Import and export geographic data from the PostGIS database using the available tools Structure spatial data using the functionality provided by a combination of PostgreSQL and PostGIS Work with a set of PostGIS functions to perform basic and advanced vector analyses Connect PostGIS with Python Learn to use programming frameworks around PostGIS Maintain, optimize, and fine-tune spatial data for long-term viability Explore the 3D capabilities of PostGIS, including LiDAR point clouds and point clouds derived from Structure from Motion (SfM) techniques Distribute 3D models through the Web using the X3D standard Use PostGIS to develop powerful GIS web applications using Open Geospatial Consortium web standards Master PostGIS Raster Who This Book Is For This book is for developers who need some quick solutions for PostGIS. Prior knowledge of PostgreSQL and spatial concepts would be an added advantage. Table of Contents Chapter 1. MOVING DATA IN AND OUT OF POSTGIS Chapter 2. STRUCTURES THAT WORK Chapter 3. WORKING WITH VECTOR DATA THE BASICS Chapter 4. WORKING WITH VECTOR DATA ADVANCED RECIPES Chapter 5. WORKING WITH RASTER DATA Chapter 6. WORKING WITH PGROUTING Chapter 7. Into the Nth Dimension Chapter 8. POSTGIS PROGRAMMING Chapter 9. POSTGIS AND THE WEB Chapter 10. MAINTENANCE OPTIMIZATION AND PERFORMANCE TUNING Chapter 11. USING DESKTOP CLIENTS Chapter 12. Introduction to Location Privacy Protection Mechanisms
PostGIS是一个开源的地理信息系统(GIS)扩展,可与PostgreSQL数据库一起使用。PostGIS教程提供了使用PostGIS进行地理数据存储,查询和分析的指导。 首先,PostGIS使用需要在PostgreSQL数据库中安装和启用PostGIS扩展。安装完毕后,可以创建一个新的空间数据库或将PostGIS添加到现有数据库中。 接下来,学习如何在PostGIS中导入和管理地理数据。可以使用常见的地理信息文件格式(如Shapefile)或使用其他GIS软件生成的数据进行导入。导入后,可以使用SQL命令查询和分析地理数据。 PostGIS支持多种地理数据类型,如点(Point),线(LineString)和面(Polygon)。可以使用这些数据类型创建空间表,然后将地理数据插入到这些表中。还可以在表中创建索引来提高查询性能,并使用规则和触发器来实现数据完整性和一致性。 除了基本的地理数据管理外,PostGIS还提供了强大的地理分析功能。例如,可以使用PostGIS函数计算两个地理对象之间的距离,或者使用缓冲区操作创建一个围绕地理对象的缓冲区区域。还可以执行空间联接操作,通过对两个地理对象进行交集、并集或差集操作来分析它们之间的空间关系。 此外,PostGIS还支持地理数据的可视化。可以使用GIS软件(如QGIS)或Web地图库(如Leaflet)来加载和显示PostGIS中的地理数据。还可以利用GeoJSON格式将地理数据导出到其他GIS工具中进行处理和分析。 总的来说,PostGIS教程是学习使用PostGIS进行地理数据存储、查询和分析的指南。通过掌握PostGIS的基本概念和操作,可以更好地利用PostgreSQL数据库构建和管理地理信息系统。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值