ArcGIS Engine calculates the distance area volume _arcgis

Source: Internet
Author: User
Tags ipoint
ArcGIS engine two development--calculate the area of Shapefile surface layer elements http://blog.csdn.net/giselite/article/details/44750349


All should learn to see AE class diagram and help, especially class diagram, in the installation directory under the diagram directory, see more natural will be handy. No more nonsense, here is a trial code I wrote


, announced, hope to help those who have the needs of children's shoes, to give them some time to save.


Using System.Runtime;
Using System.Runtime.InteropServices;
Using ESRI. Arcgis.geodatabase;
Using ESRI. Arcgis.datasourcesfile;
Using ESRI. Arcgis.geometry;

private void Form1_Click (object sender, EventArgs e)
{
Iworkspacefactory pwsf = null;
Double Darea = 0;
Try
{
Pwsf = new Shapefileworkspacefactoryclass ();
Ifeatureworkspace PWS = Pwsf.openfromfile (@ "h:\ water flooded area", 0) as Ifeatureworkspace;
Ifeatureclass PFC = Pws.openfeatureclass ("topic of water submerged area; shp");

Ifeaturecursor pfeaturecur = Pfc.search (null, FALSE);
Ifeature pfeature = Pfeaturecur.nextfeature ();
while (pfeature!= null)
{
if (PFeature.Shape.GeometryType = = Esrigeometrytype.esrigeometrypolygon)
{
Iarea Parea = Pfeature.shape as Iarea;
Darea = Darea + Parea.area;
}

Pfeature = Pfeaturecur.nextfeature ();
}

Marshal.ReleaseComObject (pfeaturecur);
}
catch (System.Exception ex)
{

}

Marshal.ReleaseComObject (PWSF);
}
========
6.5 Iproximityoperator Interface http://www.cnblogs.com/gisoracle/archive/2012/03/28/2420706.html


Introduction to 6.5.1 Iproximityoperator interface


The Iproximityoperator interface is used to get the distance of two geometries, and given a point, to find the nearest spot on the other geometry from the given point. The main Iproximityoperator interface


The methods are: Querynearespoint,returndistance, Returnnearestpoint


The Returndistance method is used to return the shortest distance between two geometric objects, and the Querynearespoint method is used to query for a reference to the point where the nearest distance from the given input point is obtained on the geometric object.


The Returnnearestpoint method is used to create and return the point of the closest distance from a given input point on a geometric object.


6.5.2 Recent point Query function development


The following code fragment demonstrates how to use the Iproximityoperator interface to get the closest point to the geometry to be queried:




Returns a point from the nearest pinputpoint on the Pgeometry
</summary>
<param name= "Pinputpoint" > Given point object </param>
<param name= "Pgeometry" > Geometry to Query </param>
<returns>the Nearest Point</returns>
Private IPoint Nearestpoint (IPoint pinputpoint, Igeometry pgeometry)
{
Try
{
Iproximityoperator pproximity = (iproximityoperator) pgeometry;
IPoint pnearestpoint = Pproximity.returnnearestpoint (Pinputpoint, esrisegmentextension.esrinoextension);
return pnearestpoint;
}
catch (Exception ERR)
{
MessageBox.Show (err.message, "hint", MessageBoxButtons.OK, MessageBoxIcon.Information);
return null;
}
}
Copy Code


The following code fragment demonstrates how to use the Iproximityoperator interface to query the distance of a given two geometric objects:



<summary>
Gets the distance of two geometries
</summary>
<param name= "Pgeometrya" > Geometry a</param>
<param name= "Pgeometryb" > Geometry b</param>
<returns> Two geometry distance </returns>
Private double Gettwogeometrydistance (igeometry Pgeometrya, Igeometry pgeometryb)
{
Iproximityoperator pprooperator = Pgeometrya as Iproximityoperator;
if (pgeometrya!=null| | Pgeometryb!=null)
{
Double distance= pprooperator.returndistance (PGEOMETRYB);
return distance;
}
Else
{
return 0;
}
}
========
Spatial relationship (calculate distance between two points, calculation range) http://xitong.iteye.com/blog/1715755


Calculate the distance between two points


1///<summary> calculate distance between two points
2///</summary>
3///<param name= "Point1" ></param>
4///<param name= "Point2" ></param>
5///<returns></returns>
6 public static double Getdistanceoftwopoints (ESRI. ArcGIS.Geometry.IPoint Point1, ESRI. ArcGIS.Geometry.IPoint Point2)
7 {
8 return math.sqrt (point1. X-point2. X) * (point1. X-point2. X) + (point1. Y-point2. Y) * (point1. Y-point2. Y));
9}


Feature translation
1 Igeometry geo=feature. Shape;
2 ((itransform2d) Geo). Move (20,20);




Calculation range


Get the N-times envelope range of the point set


1///<summary> get n times envelope range of point set
2///</summary>
3///<param name= "points" ></param>
4///<param name= "Zoominnumber" ></param>
5///<returns></returns>
6 public static Ienvelope Getbigenvelope (ipointcollection points, double zoominnumber)
7 {
8 Ienvelope result = new Envelopeclass ();
9
Double xmax = 0, xmin = 999999999999, ymax = 0, ymin = 999999999999;
11
for (int i = 0; i < points. Pointcount; i++)
13 {
ESRI. ArcGIS.Geometry.IPoint p = points.get_point (i);
if (Xmax < p.x) Xmax = p.x;
if (Ymax < p.y) ymax = p.y;
if (Xmin > p.x) xmin = p.x;
if (Ymin > p.y) ymin = p.y;
19}
Result. Xmax = Xmax + xmax-xmin;
Result. Xmin = Xmin-xmax + xmin;
Result. Ymax = Ymax + ymax-ymin;
Result. Ymin = Ymin-ymax + ymin;
24
Result of return;
26}
========

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.