public class HangpianFeatureClassGenerator : IFeatureClassGenerator
{
//解析摄区
string[] strXY;
string[] XY;
public void Generate(int inStockTaskId)
{
#region 调用获得SheQu对象
HangPianMetaDataLoader hpmdl = new HangPianMetaDataLoader();
SheQu SQ = hpmdl.LoadByInStockTaskId(inStockTaskId);
#endregion
#region 生成摄区
string ScaleStr = SQ.ScaleDefinition;
//n为SQ表中摄区的个数,暂时认为是1
int n = 1;
int begin;
int end;
string[] split2;
string[] split1;
string sub = string.Empty;
for (int i = 1; i <= n; i++)
{
split1 = ScaleStr.Split(new char[] { '+', '-' });
foreach (string a in split1)
{
if (a.Trim() != "")
{
begin = a.IndexOf('(');
end = a.IndexOf(')');
sub = a.Substring(begin + 1, end - begin - 1);
split2 = sub.Split(new char[] { ';' });
strXY = split2;
//返回需要的数组,x,y对
foreach (string b in split2)
{
if (b.Trim() != "")
{
Console.WriteLine(b);
}
}
}
}
}
IFeatureWorkspace pFeatureWorkspace = FeatureWorkspaceFactory.GenerateFeatureWorkspace();
IWorkspaceEdit pWorkspaceEdit = (IWorkspaceEdit)pFeatureWorkspace;
pWorkspaceEdit.StartEditing(true);
pWorkspaceEdit.StartEditOperation();
IFeatureClass pPolygonsClass = pFeatureWorkspace.OpenFeatureClass("ShequFeature");
IFeature pPolygonsFeaure;
pPolygonsFeaure = pPolygonsClass.CreateFeature();
//设置几何字段
IPolygon pPolygon = new PolygonClass();
IPointCollection pPointCollection = (IPointCollection)pPolygon;
IPoint pPoint;
object _missing = Type.Missing;
double x, y;
for (int i = 0; i < strXY.Length; i++)
{
XY = strXY[i].Split(new char[] { ',', ',' });
x = double.Parse(XY[0]);
y = double.Parse(XY[1]);
pPoint = new PointClass();
pPoint.PutCoords(x, y);
pPointCollection.AddPoint(pPoint, ref _missing, ref _missing);
}
pPolygon.Close();
pPolygonsFeaure.Shape = pPolygon;
//设置非几何字段
pPolygonsFeaure.set_Value(pPolygonsFeaure.Fields.FindField("ShequID"), SQ.ShequId);
pPolygonsFeaure.set_Value(pPolygonsFeaure.Fields.FindField("SliceID"), SQ.SliceId);
pPolygonsFeaure.set_Value(pPolygonsFeaure.Fields.FindField("ShequName"), SQ.Name);
pPolygonsFeaure.set_Value(pPolygonsFeaure.Fields.FindField("ShequHao"), SQ.ShequHao);
pPolygonsFeaure.set_Value(pPolygonsFeaure.Fields.FindField("Resolution"), SQ.Resolution);
pPolygonsFeaure.set_Value(pPolygonsFeaure.Fields.FindField("Scale"), SQ.Scale);
pPolygonsFeaure.set_Value(pPolygonsFeaure.Fields.FindField("StartDate"), SQ.StartDate);
pPolygonsFeaure.set_Value(pPolygonsFeaure.Fields.FindField("EndDate"), SQ.EndDate);
pPolygonsFeaure.set_Value(pPolygonsFeaure.Fields.FindField("TotalArea"), SQ.TotalArea);
pPolygonsFeaure.set_Value(pPolygonsFeaure.Fields.FindField("ImgType"), SQ.ImgType);
pPolygonsFeaure.set_Value(pPolygonsFeaure.Fields.FindField("Quality"), SQ.Quality);
pPolygonsFeaure.set_Value(pPolygonsFeaure.Fields.FindField("Orientation"), SQ.Orientation);
pPolygonsFeaure.set_Value(pPolygonsFeaure.Fields.FindField("Px"), SQ.Px);
pPolygonsFeaure.set_Value(pPolygonsFeaure.Fields.FindField("Py"), SQ.Py);
pPolygonsFeaure.set_Value(pPolygonsFeaure.Fields.FindField("Unit"), SQ.Unit);
pPolygonsFeaure.set_Value(pPolygonsFeaure.Fields.FindField("FilePath"), SQ.FilePath);
pPolygonsFeaure.Store();
#endregion
#region 生成分区
foreach (FenQu f in SQ.Fenqu)
{
ScaleStr = f.ScaleDefinition;
split1 = ScaleStr.Split(new char[] { '+', '-' });
foreach (string a in split1)
{
if (a.Trim() != "")
{
begin = a.IndexOf('(');
end = a.IndexOf(')');
sub = a.Substring(begin + 1, end - begin - 1);
split2 = sub.Split(new char[] { ';', ';' });
strXY = split2;
//返回需要的数组,x,y对
foreach (string b in split2)
{
if (b.Trim() != "")
{
Console.WriteLine(b);
}
}
}
}
pPolygonsClass = pFeatureWorkspace.OpenFeatureClass("FenquFeature");
pPolygonsFeaure = pPolygonsClass.CreateFeature();
//设置几何字段
pPolygon = new PolygonClass();
pPointCollection = (IPointCollection)pPolygon;
for (int i = 0; i < strXY.Length; i++)
{
XY = strXY[i].Split(new char[] { ',', ',' });
x = double.Parse(XY[0]);
y = double.Parse(XY[1]);
pPoint = new PointClass();
pPoint.PutCoords(x, y);
pPointCollection.AddPoint(pPoint, ref _missing, ref _missing);
}
pPolygon.Close();
pPolygonsFeaure.Shape = pPolygon;
//设置非几何字段
pPolygonsFeaure.set_Value(pPolygonsFeaure.Fields.FindField("FenquID"),f.FenquId) ;
pPolygonsFeaure.set_Value(pPolygonsFeaure.Fields.FindField("ShequID"), f.ShequID);
pPolygonsFeaure.set_Value(pPolygonsFeaure.Fields.FindField("FenquHao"), f.FenquHao);
//pPolygonsFeaure.set_Value(pPolygonsFeaure.Fields.FindField("Area"), (double)f.Area);
pPolygonsFeaure.set_Value(pPolygonsFeaure.Fields.FindField("Scale"), f.Scale);
pPolygonsFeaure.set_Value(pPolygonsFeaure.Fields.FindField("StartDate"), f.StartDate);
pPolygonsFeaure.set_Value(pPolygonsFeaure.Fields.FindField("EndDate"), f.EndDate);
pPolygonsFeaure.set_Value(pPolygonsFeaure.Fields.FindField("ImgType"), f.ImgType);
pPolygonsFeaure.set_Value(pPolygonsFeaure.Fields.FindField("Orientation"), f.Orientation);
pPolygonsFeaure.set_Value(pPolygonsFeaure.Fields.FindField("FilePath"), f.FilePath);
pPolygonsFeaure.set_Value(pPolygonsFeaure.Fields.FindField("SliceID"), f.SliceId);
pPolygonsFeaure.Store();
#endregion
#region 生成航线
foreach (HangXian h in f.Hangxian)
{
pPolygonsClass = pFeatureWorkspace.OpenFeatureClass("HangxianFeature");
pPolygonsFeaure = pPolygonsClass.CreateFeature();
//设置几何字段
IPolyline pPolyline = new PolylineClass();
pPointCollection = (IPointCollection)pPolyline;
pPoint = new PointClass();
x = GlobalFunctions.DMS2Degree(h.StartLongitudeDegree, h.StartLongitudeMinute, h.StartLongitudeSecond);
y = GlobalFunctions.DMS2Degree((int)h.StartLatitudeDegree, h.StartLatitudeMinute, h.StartLatitudeSecond);
pPoint.PutCoords(x, y);
pPointCollection.AddPoint(pPoint, ref _missing, ref _missing);
x = GlobalFunctions.DMS2Degree(h.EndLongitudeDegree, h.EndLongitudeMinute, h.EndLongitudeSecond);
y = GlobalFunctions.DMS2Degree(h.EndLatitudeDegree, h.EndLatitudeMinute, h.EndLatitudeSecond);
pPoint.PutCoords(x, y);
pPointCollection.AddPoint(pPoint, ref _missing, ref _missing);
pPolygonsFeaure.Shape = pPolyline;
//设置非几何字段
pPolygonsFeaure.set_Value(pPolygonsFeaure.Fields.FindField("SliceID"), h.ShequId);
pPolygonsFeaure.set_Value(pPolygonsFeaure.Fields.FindField("ShequID"), h.ShequId);
pPolygonsFeaure.set_Value(pPolygonsFeaure.Fields.FindField("Hangxianhao"), h.Hangxianhao);
pPolygonsFeaure.set_Value(pPolygonsFeaure.Fields.FindField("StartLongitudeDegree"), h.StartLongitudeDegree);
pPolygonsFeaure.set_Value(pPolygonsFeaure.Fields.FindField("StartLongitudeMinute"), h.StartLongitudeMinute);
pPolygonsFeaure.set_Value(pPolygonsFeaure.Fields.FindField("StartLongitudeSecond"), h.StartLongitudeSecond);
pPolygonsFeaure.set_Value(pPolygonsFeaure.Fields.FindField("StartLatitudeDegree"), h.StartLatitudeDegree);
pPolygonsFeaure.set_Value(pPolygonsFeaure.Fields.FindField("StartLatitudeMinute"), h.StartLatitudeMinute);
pPolygonsFeaure.set_Value(pPolygonsFeaure.Fields.FindField("StartLatitudeSecond"), h.StartLatitudeSecond);
pPolygonsFeaure.set_Value(pPolygonsFeaure.Fields.FindField("EndLongitudeDegree"), h.EndLongitudeDegree);
pPolygonsFeaure.set_Value(pPolygonsFeaure.Fields.FindField("EndLongitudeMinute"), h.EndLongitudeMinute);
pPolygonsFeaure.set_Value(pPolygonsFeaure.Fields.FindField("EndLongitudeSecond"), h.EndLongitudeSecond);
pPolygonsFeaure.set_Value(pPolygonsFeaure.Fields.FindField("EndLatitudeDegree"), h.EndLatitudeDegree);
pPolygonsFeaure.set_Value(pPolygonsFeaure.Fields.FindField("EndLongitudeMinute"), h.EndLatitudeMinute);
pPolygonsFeaure.set_Value(pPolygonsFeaure.Fields.FindField("EndLongitudeSecond"), h.EndLatitudeSecond);
pPolygonsFeaure.set_Value(pPolygonsFeaure.Fields.FindField("Length"), h.Length);
pPolygonsFeaure.set_Value(pPolygonsFeaure.Fields.FindField("ImgNumber"), h.ImgNumber);
pPolygonsFeaure.set_Value(pPolygonsFeaure.Fields.FindField("FilePath"), h.FilePath);
pPolygonsFeaure.set_Value(pPolygonsFeaure.Fields.FindField("HangxianID"), h.HangxianId);
pPolygonsFeaure.set_Value(pPolygonsFeaure.Fields.FindField("FenquID"), h.FenquId);
pPolygonsFeaure.Store();
#endregion
#region 生成像点
foreach (XiangDian xd in h.Xiangdian)
{
pPolygonsClass = pFeatureWorkspace.OpenFeatureClass("XiangdianFeature");
pPolygonsFeaure = pPolygonsClass.CreateFeature();
//设置几何字段
IPoint pXiangdianPoint = new PointClass();
x = GlobalFunctions.DMS2Degree(xd.LongitudeDegree, xd.LongitudeMinute, xd.LongitudeSecond);
y = GlobalFunctions.DMS2Degree(xd.LatitudeDegree, xd.LatitudeMinute, xd.LatitudeSecond);
pXiangdianPoint.PutCoords(x, y);
pPolygonsFeaure.Shape = pXiangdianPoint;
//设置非几何字段
pPolygonsFeaure.set_Value(pPolygonsFeaure.Fields.FindField("SliceID"), xd.SliceId);
pPolygonsFeaure.set_Value(pPolygonsFeaure.Fields.FindField("ShequID"), xd.ShequId);
pPolygonsFeaure.set_Value(pPolygonsFeaure.Fields.FindField("FenquID"), xd.FenquId);
pPolygonsFeaure.set_Value(pPolygonsFeaure.Fields.FindField("HangxianID"), xd.HangxianId);
pPolygonsFeaure.set_Value(pPolygonsFeaure.Fields.FindField("XiangdianHao"), xd.XiangdianHao);
//这里字段有问题
pPolygonsFeaure.set_Value(pPolygonsFeaure.Fields.FindField("LongtitudeDegree"), xd.LongitudeDegree);
pPolygonsFeaure.set_Value(pPolygonsFeaure.Fields.FindField("LongtitudeMinute"), xd.LongitudeMinute);
pPolygonsFeaure.set_Value(pPolygonsFeaure.Fields.FindField("LongtitudeSecond"), xd.LongitudeSecond);
pPolygonsFeaure.set_Value(pPolygonsFeaure.Fields.FindField("LatitudeDegree"), xd.LatitudeDegree);
pPolygonsFeaure.set_Value(pPolygonsFeaure.Fields.FindField("LatitudeMinute"), xd.LongitudeMinute);
pPolygonsFeaure.set_Value(pPolygonsFeaure.Fields.FindField("LatitudeSecond"), xd.LatitudeSecond);
pPolygonsFeaure.set_Value(pPolygonsFeaure.Fields.FindField("ImgType"), xd.ImgType);
pPolygonsFeaure.set_Value(pPolygonsFeaure.Fields.FindField("FilePath"), xd.FilePath);
pPolygonsFeaure.set_Value(pPolygonsFeaure.Fields.FindField("HangsheyiHao"), xd.HangsheyiHao);
pPolygonsFeaure.set_Value(pPolygonsFeaure.Fields.FindField("XiangdianID"), xd.XiangdianId);
pPolygonsFeaure.Store();
}
}
#endregion
}
pWorkspaceEdit.StopEditOperation();
pWorkspaceEdit.StopEditing(true);
}
}
}