I am working with ArcGis with c# and I Face some major issue and I do not reach why that issue is occurs.
I am creating a shape file using ArcGis SDK which is created successfully.
I have 500000+ data to be processed for Linestring and I want to intersect with specific region. This part of the code takes time for checking intersection to the specified regions.
This is my function For Making IGeometry list for matching lines as per regions.
private List<IGeometry> CreatePolyline1(ref DataSet ds, string logfilePath, string ViewName)
{
object obj1 = Type.Missing;
int count = 0; //ds.Tables[0].Rows.Count;
IGeometry[] geometryArray = new IGeometry[ds.Tables[0].Rows.Count];
DataSet ds1 = GetViewData("US_Regions", logfilePath); //This is For RegionDataSet for intersect.
List<IGeometry> lst = new List<IGeometry>();
try
{
do
{
if (ds.Tables[0].Rows[count]["SHAPE"] != DBNull.Value)
{
SqlGeometry Data = (SqlGeometry)ds.Tables[0].Rows[count]["SHAPE"];
bool p = false;
foreach (DataRow row in ds1.Tables[0].Rows)
{
SqlGeometry stateGeo = (SqlGeometry)row["SHAPE"];
if (stateGeo.STIntersects(Data))
{
string st = Data.ToString();
geometryArray[count] = ConvertWKTToGeometry(st, logfilePath);
lst.Add(geometryArray[count]);
p = true;
break;
}
}
if (!p)
{
ds.Tables[0].Rows.RemoveAt(count--);
}
count++;
}
} while (ds.Tables[0].Rows.Count > count);
WriteToLogFile("Complete List Geometry :=>" + ViewName, logfilePath);
}
catch (Exception ex)
{}
return lst;
}
This method is use for convert Geometry Field to IGeometry :
public IGeometry ConvertWKTToGeometry(string wkt, string logpath) { byte[] wkb = ConvertWKTToWKB(wkt); return ConvertWKBToGeometry(wkb, logpath); }
public IGeometry ConvertWKBToGeometry(byte[] wkb, string logpath)
{
IGeometryFactory3 factory = new GeometryEnvironment() as IGeometryFactory3;
try
{
ESRI.ArcGIS.Geometry.IGeometry geom;
int countin = wkb.GetLength(0);
factory.CreateGeometryFromWkbVariant(wkb, out geom, out countin);
return geom;
}
catch (Exception ex)
{
WriteToLogFile("Error In ConvertWKBToGeometry :=>>>>>" + ex.Message, logpath);
throw;
}
finally
{
Marshal.ReleaseComObject(factory);
}
}
public static byte[] ConvertWKTToWKB(string wkt)
{
WKBWriter w = new WKBWriter();
WKTReader r = new WKTReader();
return w.Write(r.Read(wkt));
}
could any one suggest me a better technique for faster out come for this process.
Aucun commentaire:
Enregistrer un commentaire