Example #1
0
 private FLine_AREAWATER Line2Model(FLine_AREAWATER FModel, string[] line)
 {
     FModel.WKT      = line[0];
     FModel.ANSICODE = line[1];
     FModel.HYDROID  = line[2];
     FModel.FULLNAME = line[3];
     FModel.MTFCC    = line[4];
     FModel.ALAND    = line[5];
     FModel.AWATER   = line[6];
     FModel.INTPTLAT = line[7];
     FModel.INTPTLON = line[8];
     return(FModel);
 }
Example #2
0
        private IFeatureBuffer SetFLine2Feature(IFeatureBuffer fb, FLine_AREAWATER model, long lineNum)
        {
            if (model.WKT.Contains("\""))
            {
                model.WKT = model.WKT.Replace("\"", "");
            }
            data = model.WKT.Split(splitWKT_AREAWATER, StringSplitOptions.None);
            if (data.Length != 3)
            {
                Log("行号[" + lineNum.ToString() + "],WKT未能正确分割,结果为:" + model.WKT);
                return(null);
            }
            type = data[0];
            cood = data[1];

            if (type.ToUpper() != "POLYGON")
            {
                Log("行号[" + lineNum.ToString() + "],WKT类型指示的值错误,错误值为:" + model.WKT);
                return(null);
            }
            string    message;
            IGeometry geometry = WKTCoordinateInfo2Polygon(cood, out message);

            if (geometry == null)
            {
                Log("行号[" + lineNum.ToString() + "]." + message + "----------" + model.WKT);
                return(null);
            }
            fb.Shape = geometry;

            #region
            fieldIndex = fields.FindField("ALAND");
            if (fieldIndex >= 0)
            {
                fb.Value[fieldIndex] = model.ALAND;
            }
            fieldIndex = fields.FindField("ANSICODE");
            if (fieldIndex >= 0)
            {
                fb.Value[fieldIndex] = model.ANSICODE;
            }
            fieldIndex = fields.FindField("AWATER");
            if (fieldIndex >= 0)
            {
                fb.Value[fieldIndex] = model.AWATER;
            }
            fieldIndex = fields.FindField("FULLNAME");
            if (fieldIndex >= 0)
            {
                fb.Value[fieldIndex] = model.FULLNAME;
            }
            fieldIndex = fields.FindField("HYDROID");
            if (fieldIndex >= 0)
            {
                fb.Value[fieldIndex] = model.HYDROID;
            }
            fieldIndex = fields.FindField("INTPTLAT");
            if (fieldIndex >= 0)
            {
                fb.Value[fieldIndex] = model.INTPTLAT;
            }
            fieldIndex = fields.FindField("INTPTLON");
            if (fieldIndex >= 0)
            {
                fb.Value[fieldIndex] = model.INTPTLON;
            }
            fieldIndex = fields.FindField("MTFCC");
            if (fieldIndex >= 0)
            {
                fb.Value[fieldIndex] = model.MTFCC;
            }
            #endregion

            return(fb);
        }
Example #3
0
        private long ReadCSV(string csvPath, string gdbPath, string fcName, long startLine, long endLine)
        {
            long total = 0;
            IWorkspaceFactory GDBWorkspaceFactory = new FileGDBWorkspaceFactoryClass();
            IWorkspace        ws  = GDBWorkspaceFactory.OpenFromFile(gdbPath, 0);
            IFeatureWorkspace fws = ws as IFeatureWorkspace;

            IFeatureClass fc = fws.OpenFeatureClass(fcName);

            fields = fc.Fields;

            IFeatureClassLoad fcl = fc as IFeatureClassLoad;

            fcl.LoadOnlyMode = true;

            long lineNum   = 0;
            long insertNum = 0;

            using (FileStream fs = new FileStream(csvPath, FileMode.Open, FileAccess.Read))
            {
                using (StreamReader sr = new StreamReader(fs, Encoding.UTF8))
                {
                    string         strLine = "";
                    IFeatureCursor fCursor = fc.Insert(true);
                    IFeatureBuffer fb      = fc.CreateFeatureBuffer();
                    string[]       line;
                    //FLine_EDGES model_EDGES = new FLine_EDGES();
                    FLine_AREAWATER model_AREAWATER = new FLine_AREAWATER();

                    while ((strLine = sr.ReadLine()) != null)
                    {
                        lineNum++;
                        if (lineNum < startLine)
                        {
                            continue;
                        }

                        //line = SplitAndCheckLine_EDGES(strLine, lineNum);
                        line = SplitAndCheckLine_AREAWATER(strLine, lineNum);

                        if (line == null)
                        {
                            continue;
                        }
                        // model_EDGES = Line2Model(model_EDGES, line);
                        model_AREAWATER = Line2Model(model_AREAWATER, line);

                        //fb = SetFLine2Feature(fb, model_EDGES, lineNum);
                        fb = SetFLine2Feature(fb, model_AREAWATER, lineNum);
                        if (fb == null)
                        {
                            continue;
                        }

                        fCursor.InsertFeature(fb);
                        insertNum++;

                        if (lineNum % 10000 == 0)
                        {
                            fCursor.Flush();
                            total = insertNum;
                        }
                        if (endLine > 0 && lineNum >= endLine)
                        {
                            fCursor.Flush();
                            total = insertNum;
                            break;
                        }
                    }
                }
            }

            fcl.LoadOnlyMode = false;

            Log("Sum:" + lineNum.ToString());
            return(total);
        }