How to improve the performance of c# program -
i trying to extract sdf file geodatabase.as new sdf file created ,the memory usage program increases.to overcome issue have tried reaseing connection sdf file , tried release resources using gc.collect() method still problem persist.
/// <summary> /// feature data geodatabase file /// </summary> /// <param name="dictionaryproperty"> schema of table </param> /// <param name="table">table connection of gdb file</param> /// <param name="sdffilepath">sdf file path</param> static void getfeaturedata(dictionary<string, property> dictionaryproperty, table table, string sdffilepath) { int filecount = 1; ; list<property> propertylist = new list<property>(); ienumerable<string> propertycoll = dictionaryproperty.select(i => i.value).where(i => i.datatype == "oid").tolist().select(i => i.propertyname); string propertyname = null; foreach (string item in propertycoll) { propertyname = item; } (int rowno = 1; rowno <= table.rowcount; rowno++) { foreach (row row in table.search("*", propertyname + "=" + rowno.tostring(), rowinstance.recycle)) { foreach (property property in dictionaryproperty.values) { property objproperty = new property(); objproperty.propertyname = property.propertyname; objproperty.datatype = property.datatype; switch (property.datatype) { case "smallinteger": if (row.isnull(property.propertyname)) { objproperty.propertydata = ""; } else { objproperty.propertydata = row.getshort(property.propertyname).tostring(); } break; case "geometry": switch (row.getgeometry().geometrytype.tostring()) { case "point": pointshapebuffer pointgeometry = row.getgeometry(); objproperty.geometrytype = property.geometrytype; objproperty.geometrydata = pointgeometry.point.x + " " + pointgeometry.point.y; break; objproperty.geometrydata = coord; objproperty.propertydata = coord; objproperty.geometrytype = property.geometrytype; coord = string.empty; break; case "polygon": break; } break; case "globalid": break; } propertylist.add(objproperty); } insertfeaturedata(table, propertylist, sdffilepath); propertylist.clear(); } } console.writeline(filecount + "file completed"); filecount++; } /// <summary> /// insert feature data sdf file path /// </summary> /// <param name="table"></param> /// <param name="propertylist">schema defination</param> /// <param name="sdffilepath"></param> static void insertfeaturedata(table table, list<property> propertylist, string sdffilepath) { iconnection con = openfdosdfconnection(sdffilepath); iinsert insertcommand = (iinsert)con.createcommand(osgeo.fdo.commands.commandtype.commandtype_insert); insertcommand.setfeatureclassname(gettablename(table)); foreach (property objproperty in propertylist) { switch (objproperty.datatype) { case "oid": if (!string.isnullorempty(objproperty.propertydata)) { insertcommand.propertyvalues.add(new propertyvalue(objproperty.propertyname, new int64value(convert.toint64(objproperty.propertydata)))); } else { insertcommand.propertyvalues.add(new propertyvalue(objproperty.propertyname, null)); } break; case "geometry": switch (objproperty.geometrytype) { case "point": if (!(objproperty.geometrydata == "")) { fgfgeometryfactory factory = new fgfgeometryfactory(); directpositioncollection pcollection = new directpositioncollection(); string[] points = objproperty.geometrydata.split(); insertcommand.propertyvalues.add(new propertyvalue("geometry", new geometryvalue(factory.getfgf(factory.createpoint(factory.createpositionxy(convert.todouble(points[0]), convert.todouble(points[1]))))))); } } } insertcommand.execute(); insertcommand.dispose(); con.close(); }
Comments
Post a Comment