Exemplo n.º 1
0
        public FeatureClassV1(Dataset dataset, OSGeo_v1.OGR.Layer layer)
        {
            _dataset  = dataset;
            _ogrLayer = layer;

            OSGeo_v1.OGR.FeatureDefn defn = layer.GetLayerDefn();
            _name = defn.GetName();
            if (dataset.ConnectionString.ToLower().EndsWith(".dxf"))
            {
                try
                {
                    System.IO.FileInfo fi = new System.IO.FileInfo(dataset.ConnectionString);
                    _name = fi.Name;
                }
                catch { }
            }
            _fields = new Fields();
            for (int i = 0; i < defn.GetFieldCount(); i++)
            {
                OSGeo_v1.OGR.FieldDefn fdefn = defn.GetFieldDefn(i);
                Field field = new Field(fdefn.GetName());

                switch (fdefn.GetFieldTypeName(fdefn.GetFieldType()).ToLower())
                {
                case "integer":
                    if (_idFieldName == String.Empty)
                    {
                        _idFieldName = field.name;
                    }
                    field.type = FieldType.integer;
                    break;

                case "real":
                    field.type = FieldType.Double;
                    break;

                case "string":
                    field.type = FieldType.String;
                    field.size = fdefn.GetWidth();
                    break;
                }
                _fields.Add(field);
            }

            _countFeatures = (int)layer.GetFeatureCount(1);
            OSGeo_v1.OGR.Envelope env = new OSGeo_v1.OGR.Envelope();
            layer.GetExtent(env, 1);
            _envelope = new Envelope(env.MinX, env.MinY, env.MaxX, env.MaxY);

            switch (defn.GetGeomType())
            {
            case OSGeo_v1.OGR.wkbGeometryType.wkbPoint:
                _geomType = geometryType.Point;
                break;

            case OSGeo_v1.OGR.wkbGeometryType.wkbLineString:
            case OSGeo_v1.OGR.wkbGeometryType.wkbMultiLineString:
                _geomType = geometryType.Polyline;
                break;

            case OSGeo_v1.OGR.wkbGeometryType.wkbPolygon:
            case OSGeo_v1.OGR.wkbGeometryType.wkbMultiPolygon:
                _geomType = geometryType.Polygon;
                break;
            }
        }