内容摘要 | |||||
很多线划图数据进ArcSDE库中都会有些对象转换不进去。这些对象有很大一部分是由于数据本身有自相交的情况。如果这些线划图数据只是用来做底图,而不需要做对象分析。则可以采用数据简单化操作后再转换入ArcSDE中。具体操作如下例子: |
delphi
//简单拓扑一个对象
procedure IsSimple(var PGeoMetry: IGeoMetry);
var
pTopo : ITopologicalOperator;
PGeoMetryCollect : IGeoMetryCollection;
ShapeType : TOleEnum;
OldGeoMetry : IGeoMetry;
begin
if IsEmpty(PGeoMetry) then Exit;
OldGeoMetry := CopyGeoMetry(PGeoMetry); //拷贝一个原始的对象,因为 有些IsSimple后,原来不为空,处理后为空
PGeoMetry.Get_GeometryType(ShapeType);
if ShapeType = esriGeometryPoint then Exit;
if ShapeType = esriGeometryRing then
begin
PGeoMetry := CreatePolygonfromRing(PGeoMetry as IRing);
end;
PGeoMetryCollect := PGeoMetry as IGeoMetryCollection;
try
PGeoMetryCollect.GeometriesChanged;
pTopo := PGeoMetry as ITopologicalOperator;
pTopo.Simplify;
if IsEmpty(PGeoMetry) then
begin
PGeoMetry := OldGeoMetry;
end;
except
end;
end;
C#
/处理自相交对象
public static bool IsSimple(ref IGeometry PGeoMetry)
{
if (PGeoMetry == null)
{
return false;//不用处理
}
if (PGeoMetry.GeometryType == esriGeometryType.esriGeometryPoint) //不做任何处理
{
return false;//不用处理
}
IGeometry oldGeoMetry = CopyGeoMetry(PGeoMetry); //拷贝一个原始的对象,因为有些IsSimple后,原来不为空,处理后为空
if (PGeoMetry.GeometryType == esriGeometryType.esriGeometryRing) //不做任何处理
{
PGeoMetry = CreatePolygonfromRing((IRing)(PGeoMetry));
}
IGeometryCollection PGeoMetryCollect = PGeoMetry as IGeometryCollection;
PGeoMetryCollect.GeometriesChanged();
ITopologicalOperator pTopo = PGeoMetry as ITopologicalOperator;
pTopo.Simplify();
if (IsEmpty(PGeoMetry))
{
PGeoMetry = oldGeoMetry;
return false;
}
else
return true;//对象修改
}
//C#例子
IGeometry SimplifyGeometry(IGeometry geom)
{
if (geom == null)
return null;
ITopologicalOperator2 topoOp = geom as ITopologicalOperator2;
topoOp.IsKnownSimple_2 = false;
switch (geom.GeometryType)
{
case esriGeometryType.esriGeometryPolygon:
{
IPolygon poly = (IPolygon)geom;
poly.SimplifyPreserveFromTo();
return poly;
}
case esriGeometryType.esriGeometryPolyline:
{
IPolyline polyLineGeom = (IPolyline)geom;
polyLineGeom.SimplifyNetwork();
return polyLineGeom;
}
default:
{
topoOp.Simplify();
return (IGeometry)topoOp;
}
}
}