|
|
|
|
using ESRI.ArcGIS.Geodatabase;
|
|
|
|
|
using ESRI.ArcGIS.Geometry;
|
|
|
|
|
using GaussCalculateLibrary;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
|
|
namespace Kingo.RuleCheck
|
|
|
|
|
{
|
|
|
|
|
public class RuleCommon
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 计算图形面积
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="geo"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static double GetArea(IGeometry geo)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
// 1、获得投影
|
|
|
|
|
string SphName = geo.SpatialReference.Name.ToString().ToUpper();
|
|
|
|
|
// 2、获得椭球
|
|
|
|
|
ICoordinate coordinate = CoordinateFactory.CreateCoordinate();
|
|
|
|
|
if (SphName.Contains("XIAN_1980") || SphName.Contains("XIAN1980"))
|
|
|
|
|
{
|
|
|
|
|
coordinate = CoordinateFactory.CreateCoordinate(GaussCalculateLibrary.Spheroid.SphXian80);
|
|
|
|
|
}
|
|
|
|
|
else if (SphName.Contains("BEIJING_1954") || SphName.Contains("BEIJING1954"))
|
|
|
|
|
{
|
|
|
|
|
coordinate = CoordinateFactory.CreateCoordinate(GaussCalculateLibrary.Spheroid.SphBeijing54);
|
|
|
|
|
}
|
|
|
|
|
else if (SphName.Contains("WGS_1984") || SphName.Contains("WGS1984"))
|
|
|
|
|
{
|
|
|
|
|
coordinate = CoordinateFactory.CreateCoordinate(GaussCalculateLibrary.Spheroid.SphWGS84);
|
|
|
|
|
}
|
|
|
|
|
else if (SphName.Contains("CGCS_2000") || SphName.Contains("CGCS2000"))
|
|
|
|
|
{
|
|
|
|
|
coordinate = CoordinateFactory.CreateCoordinate(GaussCalculateLibrary.Spheroid.SphCGCS2000);
|
|
|
|
|
}
|
|
|
|
|
else if (geo.SpatialReference is IGeographicCoordinateSystem && (SphName.Equals("GCS_China_Geodetic_Coordinate_System_2000", StringComparison.CurrentCultureIgnoreCase) || SphName.Contains("GCS_China") || SphName.Contains("Geodetic_Coordinate_System_2000")))
|
|
|
|
|
{
|
|
|
|
|
coordinate = CoordinateFactory.CreateCoordinate(GaussCalculateLibrary.Spheroid.SphCGCS2000Geo);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
// 3、计算面积
|
|
|
|
|
|
|
|
|
|
double PolygonArea = 0.0;
|
|
|
|
|
// 4、保留两位小数
|
|
|
|
|
PolygonArea = Math.Round(coordinate.CalculateTerranArea(geo), 2, MidpointRounding.AwayFromZero);
|
|
|
|
|
return PolygonArea;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
throw ex;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 查询相交总面积
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="geo"></param>
|
|
|
|
|
/// <param name="featureClass"></param>
|
|
|
|
|
/// <param name="whereClause"></param>
|
|
|
|
|
/// <param name="geoWKID"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static double GetIntersectArea(IGeometry geo, IFeatureClass featureClass, string whereClause, int geoWKID)
|
|
|
|
|
{
|
|
|
|
|
IGeoDataset pGeoDataset = (IGeoDataset)featureClass;
|
|
|
|
|
ISpatialReference pSpatialReference = pGeoDataset.SpatialReference;
|
|
|
|
|
if (pSpatialReference.FactoryCode != geoWKID && (geo.SpatialReference == null || geo.SpatialReference.FactoryCode != pSpatialReference.FactoryCode))
|
|
|
|
|
{
|
|
|
|
|
geo.Project(pSpatialReference);
|
|
|
|
|
}
|
|
|
|
|
ISpatialFilter spatialFilter = new SpatialFilterClass()
|
|
|
|
|
{
|
|
|
|
|
Geometry = geo,
|
|
|
|
|
WhereClause = whereClause
|
|
|
|
|
};
|
|
|
|
|
IFeatureCursor featureCursor = featureClass.Search(spatialFilter, true);
|
|
|
|
|
IFeature feature = featureCursor.NextFeature();
|
|
|
|
|
double intersectMJ = 0;
|
|
|
|
|
while (feature != null)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
feature = featureCursor.NextFeature();
|
|
|
|
|
IGeometry geoIntersect = CheckHelper.CommonHelper.InterSect(geo, feature.ShapeCopy);
|
|
|
|
|
if (geoIntersect != null)
|
|
|
|
|
{
|
|
|
|
|
intersectMJ += GetArea(geoIntersect);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return intersectMJ;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取线状地物宽度
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="geo"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static double GetGeometryWidth(IGeometry geo)
|
|
|
|
|
{
|
|
|
|
|
IArea iarea = geo as IArea;
|
|
|
|
|
if (iarea == null)
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
double area = Math.Abs(iarea.Area);
|
|
|
|
|
if (area <= 0)
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
ITopologicalOperator2 topo2 = geo as ITopologicalOperator2;
|
|
|
|
|
IPolyline line = topo2.Boundary as IPolyline;
|
|
|
|
|
if (line == null)
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
double length = line.Length;
|
|
|
|
|
if (length <= 0 || length.Equals(double.NaN))
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
//按照一元二次方程求解宽度
|
|
|
|
|
//长=X,宽=Y,周长=C,面积=S
|
|
|
|
|
//(X+Y)*2=C
|
|
|
|
|
// X*Y = S
|
|
|
|
|
//由上计算出:Y^2-(C/2)Y+S=0;
|
|
|
|
|
//二元一次方程求解常量
|
|
|
|
|
double a = 1;
|
|
|
|
|
double b = -(length / 2);//-(C/2)
|
|
|
|
|
double c = area;//S
|
|
|
|
|
double d = b * b - 4 * a * c;
|
|
|
|
|
double Y = Math.Round(area / (length / 2), 1, MidpointRounding.AwayFromZero);
|
|
|
|
|
if (d > 0)
|
|
|
|
|
{
|
|
|
|
|
double x1 = ((-b) - Math.Sqrt(d)) / 2;
|
|
|
|
|
double x2 = ((-b) + Math.Sqrt(d)) / 2;
|
|
|
|
|
if (x1 > 0 && Math.Abs(x1 - Y) < Math.Abs(x2 - Y))
|
|
|
|
|
{
|
|
|
|
|
Y = Math.Round(x1, 1, MidpointRounding.AwayFromZero);
|
|
|
|
|
}
|
|
|
|
|
else if (x2 > 0 && Math.Abs(x2 - Y) < Math.Abs(x1 - Y))
|
|
|
|
|
{
|
|
|
|
|
Y = Math.Round(x2, 1, MidpointRounding.AwayFromZero);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Y = Math.Round(area / (length / 2), 1, MidpointRounding.AwayFromZero);
|
|
|
|
|
}
|
|
|
|
|
return Y;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
throw ex;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|