Monday 10 July 2017

shapefile - How to reproject spatial data using free libraries?


How can I use free libraries to transform spatial data?


For example, I want to change the projection of a Shapefile within the code of my C# web application. How do I do that?



Answer



You can try the DotSpatial.Projections library.


The website lists an example "Converting from a Geographic Coordinate System to a Projected Coordinate System":


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 DotSpatial.Projections;

namespace WindowsFormsApplication1
{
public partial class Form1 : Form

{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
//Sets up a array to contain the x and y coordinates
double[] xy = new double[2];

xy[0] = 0;
xy[1] = 0;
//An array for the z coordinate
double[] z = new double[1];
z[0] = 1;
//Defines the starting coordiante system
ProjectionInfo pStart = KnownCoordinateSystems.Geographic.World.WGS1984;
//Defines the ending coordiante system
ProjectionInfo pEnd = KnownCoordinateSystems.Projected.NorthAmerica.USAContiguousLambertConformalConic;
//Calls the reproject function that will transform the input location to the output locaiton

Reproject.ReprojectPoints(xy, z, pStart, pEnd, 0, 1);
Interaction.MsgBox("The points have been reporjected.");
}
}
}

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...