C#开发ArcGIS Engine根据坐标提取对应区的属性
发布网友
发布时间:2022-04-12 14:12
我来回答
共6个回答
懂视网
时间:2022-04-12 18:33
sqlserver目前已经可以支持地理空间字段了,也就是 geometry API地址: http://msdn.microsoft.com/zh-cn/LIBRARY/cc280487.aspx 创建表和geometry字段以及插入点,线,多边形的sql如下: IF OBJECT_ID ( dbo.SpatialTable, U ) IS NOT NULL DROP TABLE dbo.Sp
sqlserver目前已经可以支持地理空间字段了,也就是 geometry
API地址:
http://msdn.microsoft.com/zh-cn/LIBRARY/cc280487.aspx
创建表和geometry字段以及插入点,线,多边形的sql如下:
IF OBJECT_ID ( 'dbo.SpatialTable', 'U' ) IS NOT NULL
DROP TABLE dbo.SpatialTable;
GO
CREATE TABLE SpatialTable
( id int IDENTITY (1,1),
geom geometry,
adress varchar );
GO
INSERT INTO SpatialTable (geom)
VALUES (geometry::STGeomFromText('POINT (20 180)', 4326));
INSERT INTO SpatialTable (geom)
VALUES (geometry::STGeomFromText('LINESTRING (100 100, 20 180, 180 180)', 4326));
INSERT INTO SpatialTable (geom)
VALUES (geometry::STGeomFromText('POLYGON ((0 0, 150 0, 150 150, 0 150, 0 0))', 4326));
GO
ps: 4326是空间引用标识符
(SRID) 一般写0或者4326
存入表中的geom字段如下:
查询语句
假如我们在数据库中存了很多坐标点的地址
选取圆形区域范围的 地址---也就是 圆心到半径范围内的所有点
DECLARE @g geometry;
set @g = geometry::STGeomFromText('POINT(104.12765 30.60445)', 4326)
SELECT address,geom.STY,geom.STX from SpatialTable where geom.STDistance(@g)<=0.005
PS:这里diatance的单位是 英里
查询出的结果如图
选取多边形
DECLARE @g geometry;
set @g = geometry::STGeomFromText('POLYGON ((104.12189573049204 30.608145728994504,104.12223905324595 30.60282680842528,104.13262456655161 30.603122311674902,104.13176625966685 30.610066378528995,104.12189573049204 30.608145728994504,104.12189573049204 30.608145728994504))',4326)
SELECT address from SpatialTable
where geom.STIntersects(@g)=1
查询出的结果如图
热心网友
时间:2022-04-12 15:41
在AE中这叫点选查询,其中你可以用你自己的坐标来替换 下面的
IMap pMap = axMapControl1.Map;
IActiveView pActiveView = pMap as IActiveView;
IFeatureLayer pFeatureLayer = pMap.get_Layer(0) as IFeatureLayer;
IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass;
//设置点击点的位置
IPoint point = pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(e.x, e.y);
ITopologicalOperator pTOpo = point as ITopologicalOperator;
double length;
length = ConvertPixelsToMapUnits(pActiveView, 4);
IGeometry pBuffer = pTOpo.Buffer(length);
IGeometry pGeomentry = pBuffer.Envelope;
//空间滤过器
ISpatialFilter pSpatialFilter = new SpatialFilter();
pSpatialFilter.Geometry = pGeomentry;
//根据被选择要素的不同,设置不同的空间滤过关系
switch (pFeatureClass.ShapeType)
{
case esriGeometryType.esriGeometryPoint:
pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelContains;
break;
case esriGeometryType.esriGeometryPolyline:
pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelCrosses;
break;
case esriGeometryType.esriGeometryPolygon:
pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
break;
}
IFeatureSelection pFSelection = pFeatureLayer as IFeatureSelection;
pFSelection.SelectFeatures(pSpatialFilter, esriSelectionResultEnum.esriSelectionResultNew, false);
ISelectionSet pSelectionset = pFSelection.SelectionSet;
ICursor pCursor;
pSelectionset.Search(null, true, out pCursor);
IFeatureCursor pFeatCursor = pCursor as IFeatureCursor;
IFeature pFeature = pFeatCursor.NextFeature();
while (pFeature != null)
{
pMap.SelectFeature(pFeatureLayer, pFeature);
pFeature = pFeatCursor.NextFeature();
pFeture.get_value("");//在这里你可以写上想要获取的属性的字段
}
pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphicSelection, null, null);
上述的自定义函数是将距离的转换
private double ConvertPixelsToMapUnits(IActiveView pActiveView, double pixelUnits)
{
// Uses the ratio of the size of the map in pixels to map units to do the conversion
IPoint p1 = pActiveView.ScreenDisplay.DisplayTransformation.VisibleBounds.UpperLeft;
IPoint p2 = pActiveView.ScreenDisplay.DisplayTransformation.VisibleBounds.UpperRight;
int x1, x2, y1, y2;
pActiveView.ScreenDisplay.DisplayTransformation.FromMapPoint(p1, out x1, out y1);
pActiveView.ScreenDisplay.DisplayTransformation.FromMapPoint(p2, out x2, out y2);
double pixelExtent = x2 - x1;
double realWorldDisplayExtent = pActiveView.ScreenDisplay.DisplayTransformation.VisibleBounds.Width;
double sizeOfOnePixel = realWorldDisplayExtent / pixelExtent;
return pixelUnits * sizeOfOnePixel;
}
热心网友
时间:2022-04-12 16:59
这是c#中的“属性”
假如某个类中有一个成员变量(字段),一般是不允许外部访问的,为了安全性
如果要访问它,必须通过“属性”来访问,例如:
private int Id; //这是一个成员变量,private表示是私有的,外部不可访问
public int ID
{
get { return id; } //当外部访问“属性”ID时,返回id的值
set { id = value; } //当外部为“属性”ID赋值时,将id赋值为value,value就是外部为“属性”ID所赋的值
}
PS:你可以在set和get中写一些隐藏的逻辑来控制这个访问和赋值的过程,这对外部是不可见的
比如
set {
if(value==0)
id = 1;
else
id=value;
}
这样当外部将ID赋值为0时,id里的值实际上是1 8
热心网友
时间:2022-04-12 18:34
如果是地图 区的定义应该是长方的吧。
判断一个点是否在一个长方形中,这个函数很容易写。X1<x<X2,Y1<y<y2
Draw2d也有区域之间相交计算的函数。不过你这个是点跟区域的交
不知你这个区域怎么定的,如果是自定的多边形,可以用给的函数算,也可以自己写一个划分三角形然后分别判断的。
热心网友
时间:2022-04-12 20:25
可以的 方法是便利坐标点,利用每个点再区域里面搜包含的,然后读取属性 不是很难
热心网友
时间:2022-04-12 22:33
不能