Exemple #1
0
        /// <summary>
        ///     Creates the scratch workspace.
        /// </summary>
        /// <param name="scratchConnectionFile">The scratch connection file.</param>
        /// <param name="fallbackScratchName">Name of the fallback scratch.</param>
        /// <returns>
        ///     Returns a <see cref="IWorkspace" /> representing the temporary workspace that is either local or in-memory.
        /// </returns>
        protected IWorkspace CreateScratchWorkspace(string scratchConnectionFile, string fallbackScratchName)
        {
            if (string.IsNullOrEmpty(scratchConnectionFile))
            {
                IScratchWorkspaceFactory2 factory = new ScratchWorkspaceFactoryClass();
                return(factory.DefaultScratchWorkspace);
            }

            if (!scratchConnectionFile.EndsWith(".gdb", StringComparison.InvariantCultureIgnoreCase))
            {
                scratchConnectionFile = Path.Combine(scratchConnectionFile, fallbackScratchName);
            }

            Log.Info("");
            Log.Info("Connecting to the geodatabase specified by the {0} file.", Path.GetFileName(scratchConnectionFile));

            var fgdb = new FileGDBWorkspaceFactoryClass();

            if (!fgdb.IsWorkspace(scratchConnectionFile) && Directory.Exists(scratchConnectionFile))
            {
                Directory.Delete(scratchConnectionFile, true);
            }

            if (!Directory.Exists(scratchConnectionFile))
            {
                var name = fgdb.Create(Path.GetDirectoryName(scratchConnectionFile), Path.GetFileName(scratchConnectionFile), null, 0);
                return(((IName)name).Open() as IWorkspace);
            }

            var workspace = fgdb.OpenFromFile(scratchConnectionFile, 0);

            return(workspace);
        }
Exemple #2
0
        /// <summary>
        /// Creates the photo featureclass.
        /// </summary>
        /// <param name="featureclassname">The featureclassname.</param>
        /// <returns>IFeatureClass for GPS Photos</returns>
        private IFeatureClass CreatePhotoFeatureclass(string featureclassname)
        {
            IScratchWorkspaceFactory scratchWorkspaceFactory = new ScratchWorkspaceFactoryClass();
            IWorkspace        scratchWorkspace = scratchWorkspaceFactory.CreateNewScratchWorkspace();
            IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)scratchWorkspace;

            return(this.CreatePhotoFeatureclass((IWorkspace)featureWorkspace, featureclassname));
        }
Exemple #3
0
        } // getFCNames

        public void doWork()
        {
            Log.p("doWork started...");
            String sdeconnfname = mSdeConnFileName; // "c:\\t\\test.sde";
            String tabnames     = mTabName;         // "T.TAB1,T.TAB2";

            Log.p("Open the source gdb");
            IWorkspaceFactory wspFact = new SdeWorkspaceFactoryClass();
            IWorkspace        wsp     = wspFact.OpenFromFile(sdeconnfname, 0);

            Log.p("Get FC names");
            IEnumNameEdit edtNames = getFCNames(wsp, tabnames);
            IEnumName     names    = (IEnumName)edtNames;

            Log.p("Create a scratch workspace factory");
            IScratchWorkspaceFactory scrWspFact = new ScratchWorkspaceFactoryClass();
            IWorkspace scrWsp     = scrWspFact.CreateNewScratchWorkspace();
            IDataset   dset       = (IDataset)scrWsp;
            IName      scrWspName = dset.FullName;

            Log.p("Create a Transfer object and a name mapping");
            IGeoDBDataTransfer trans        = new GeoDBDataTransferClass();
            IEnumNameMapping   nameMaps     = null;
            Boolean            hasConflicts = trans.GenerateNameMapping(
                names, scrWspName, out nameMaps);

            if (hasConflicts)
            {
                throw new ArgumentException("Name mapping has conflicts.");
            }

            bool          expData    = mNeedData;
            string        fname      = mExpFileName;
            bool          getMeta    = mNeedMeta;
            bool          compressed = false;
            bool          binaryGeom = true;
            IGdbXmlExport exp        = new GdbExporterClass();

            if (expData == false)
            {
                Log.p(String.Format("Export schema (u need sdeexport for data); file [{0}], metadata [{1}]",
                                    fname, getMeta));
                exp.ExportDatasetsSchema(nameMaps, fname, compressed, getMeta);
            }
            else
            {
                Log.p(String.Format("Export schema&data; file [{0}], metadata [{1}]",
                                    fname, getMeta));
                exp.ExportDatasets(nameMaps, fname, binaryGeom, compressed, getMeta);
            }

            Log.p("OK, xml writed.", "both");
        } // method doWork
Exemple #4
0
        /// <summary>
        ///     Initializes the route locator for the route.
        /// </summary>
        /// <param name="filter">An optional filter used to use a subset of the route data.</param>
        /// <param name="source">The source.</param>
        /// <returns>
        ///     Returns a <see cred="IRouteLocatorOperations2" /> represents the route locator.
        /// </returns>
        private IRouteLocatorOperations2 GetRouteLocatorOperations(IQueryFilter filter, IFeatureClass source)
        {
            IRouteLocatorOperations2 locator = new RouteLocatorOperationsClass();

            locator.RouteLocator     = this.Locator;
            locator.RouteIDFieldName = this.Locator.RouteIDFieldName;

            if (source.HasOID && (filter != null && !string.IsNullOrEmpty(filter.WhereClause)))
            {
                IScratchWorkspaceFactory2 factory = new ScratchWorkspaceFactoryClass();
                var selectionContainer            = factory.DefaultScratchWorkspace;

                var selection = source.Select(filter, esriSelectionType.esriSelectionTypeIDSet, esriSelectionOption.esriSelectionOptionNormal, selectionContainer);
                locator.InputFeatureSelection = selection;
            }
            else
            {
                locator.InputFeatureClass = source;
            }

            return(locator);
        }
Exemple #5
0
        /// <summary>
        /// Cria um shapefile a partir de um featureCursor
        /// </summary>
        /// <param name="feature">Feature desejada</param>
        public static void CriarShapefile(IFeatureLayer fLayer,
                                        IFeature feature,
                                        string pasta,
                                        IActiveView activeView,
                                        bool adicionarSaidaNoMapa,
                                        IFeatureWorkspace pFeatureWorkspaceShp)
        {
            if (feature != null)
            {
                #region Deletando shapefiles que possam existir já no diretório
                DirectoryInfo dirInf = new DirectoryInfo(pasta);
                FileInfo[] fi = dirInf.GetFiles();
                for (int i = 0; i < fi.Length; i++)
                {
                    if (fi[i].Name.Contains(fLayer.FeatureClass.AliasName) && !fi[i].Name.Contains(".lock"))
                    {
                        fi[i].Delete();
                    }
                }
                #endregion

                IWorkspace pScratchWorkspace;
                IScratchWorkspaceFactory pScratchWorkspaceFactory;
                pScratchWorkspaceFactory = new ScratchWorkspaceFactoryClass();
                pScratchWorkspace = pScratchWorkspaceFactory.DefaultScratchWorkspace;
                IFeatureSelection pNewSelSet = fLayer as IFeatureSelection;
                IEnvelope pEnv = activeView.Extent.Envelope;
                IGeometry pEnvGeo = pEnv as IEnvelope;
                ISpatialFilter pSF = new SpatialFilterClass();
                pSF.Geometry = pEnvGeo;
                pSF.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;

                IQueryFilter qf = new QueryFilterClass();

                qf.WhereClause = (fLayer as IFeatureLayerDefinition).DefinitionExpression;
                pNewSelSet.SelectFeatures(qf, esriSelectionResultEnum.esriSelectionResultNew, false);

                Geoprocessor gp = new Geoprocessor();
                gp.AddOutputsToMap = adicionarSaidaNoMapa;

                FeatureClassToShapefile fcToShapeFile = new FeatureClassToShapefile();

                fcToShapeFile.Input_Features = fLayer;
                fcToShapeFile.Output_Folder = pasta;

                IGeoProcessorResult result = gp.Execute(fcToShapeFile, null) as IGeoProcessorResult;
                string nomeArquivoSaida = gp.GetMessage(3);

                IFeatureClass pFeatureClassShp = pFeatureWorkspaceShp.OpenFeatureClass(fLayer.FeatureClass.AliasName);

                GisUtils.TratarSubtiposDominiosShapefile(fLayer, pasta, pFeatureWorkspaceShp, pFeatureClassShp);

                pFeatureClassShp = null;
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }
        }
Exemple #6
0
        private ArrayList ProcessPotentialGapErrors(ArrayList pointPairs, ITopology topology, IFeatureClass sourceFC,
			double limitRadians, bool allowPinches)
        {
            ArrayList theReturn = new ArrayList();

            // We have a list of pairs of points on opposite sides of a gap which are
            // within the tolerance distances. We need to calculate the angles
            /*
             * Format of the "pair" is IndexPoint[6]
             * [0] - thePoint
             * [1] - theOtherPoint
             * [2] - point preceding thePoint in source feature shape
             * [3] - point following thePoint in source feature shape
             * [4] - point preceding theOtherPoint in source feature shape
             * [5] - point following theOtherPoint in source feature shape
             */
            int count = 0;
            IScratchWorkspaceFactory theFactory = new ScratchWorkspaceFactoryClass();

            for (int i = 0; i < pointPairs.Count; i++)
            {
                IndexPoint[] thePair = (IndexPoint[])pointPairs[i];

                // Construct line segments and compare angles
                ILine[] theLines = new ILine[2];
                ILine[] theOtherLines = new ILine[2];
                if (thePair[2] != null) theLines[0] = this.ConstructLine(thePair[2].X, thePair[2].Y, thePair[0].X, thePair[0].Y);
                if (thePair[3] != null) theLines[1] = this.ConstructLine(thePair[0].X, thePair[0].Y, thePair[3].X, thePair[3].Y);
                if (thePair[4] != null) theOtherLines[0] = this.ConstructLine(thePair[4].X, thePair[4].Y, thePair[1].X, thePair[1].Y);
                if (thePair[5] != null) theOtherLines[1] = this.ConstructLine(thePair[1].X, thePair[1].Y, thePair[5].X, thePair[5].Y);

                bool bFoundError = false;

                for (int j = 0; j < theLines.Length; j++)
                {
                    for (int k = 0; k < theOtherLines.Length; k++)
                    {
                        // Eval angle. If it is less than the limit, Create an error and add it to the collection
                        double angleRadians = this.EvalAngle(theLines[j], theOtherLines[k]);
                        if (double.IsNaN(angleRadians) == false)
                        {
                            if (angleRadians >= 0 && angleRadians < limitRadians)
                            {
                                // Error point will be 1/2 way between points
                                ILine theGap = this.ConstructLine(thePair[0].X, thePair[0].Y, thePair[1].X, thePair[1].Y);
                                double theGapSize = theGap.Length;

                                IPolyline theGapPolyline = new PolylineClass();
                                theGapPolyline.Project(SpatialReferenceHelper.BCAlbersSpatialReference);
                                ((ISegmentCollection)theGapPolyline).AddSegment((ISegment)theGap, ref this._missing, ref this._missing);
                                theGapPolyline.Project(SpatialReferenceHelper.GeographicReference);

                                IPoint theErrorPoint = new PointClass();
                                theGapPolyline.QueryPoint(esriSegmentExtension.esriNoExtension, 0.5, true, theErrorPoint);

                                if (allowPinches || this.IsPinch(
                                    theErrorPoint,
                                    theGapPolyline,
                                    sourceFC,
                                    theFactory.DefaultScratchWorkspace
                                    ) == false)
                                {
                                    IDataset theDataset = (IDataset)sourceFC;

                                    PotentialError thePError = new PotentialError();
                                    thePError.AngleDegrees = angleRadians * 180 / Math.PI;
                                    thePError.ErrorPoint = theErrorPoint;
                                    thePError.FeatureClassName = theDataset.Name;
                                    thePError.FromPoint = theGapPolyline.FromPoint;
                                    thePError.GapSize = theGapSize;
                                    thePError.OtherOID = thePair[1].SourceFeatureID;
                                    thePError.OtherPointIndex = thePair[1].SourcePointIndex;
                                    thePError.SourceOID = thePair[0].SourceFeatureID;
                                    thePError.SourcePointIndex = thePair[0].SourcePointIndex;
                                    thePError.ToPoint = theGapPolyline.ToPoint;

                                    theReturn.Add(thePError);
                                }

                                bFoundError = true;
                            }
                        }
                        if (bFoundError)
                            break;
                    }
                    if (bFoundError)
                        break;
                }

                if (++count % 500 == 0)
                    this.LogMessage("Processed gap " + count + " of " + pointPairs.Count);
            }

            return theReturn;
        }
Exemple #7
0
        /// <summary>
        /// ��ӱ߼��
        /// </summary>
        /// <param name="pMatchEdgeFeatureClass">Ҫ���нӱ߼���Ҫ��</param>
        /// <param name="szSql">���Թ�������</param>
        /// <param name="ipGriddingline"></param>
        /// <param name="nFieldArray">����ƥ���ֶ������б�</param>
        /// <param name="dblTolerance">�ݴ�ֵ</param>
        /// <param name="ipErrorFilterEnvelop"></param>
        /// <param name="sOIDs">�ӱ߼��Ķ���OID</param>
        /// <param name="sCheckInfos">�ӱ߼��ÿ����Ϣ</param>
        /// <returns></returns>
        private bool MatchEdgeCheckPolygon(IFeatureClass pMatchEdgeFeatureClass, string szSql, IPolyline ipGriddingline,
                                           List<int> nFieldArray, double dblTolerance, IEnvelope ipErrorFilterEnvelop,
                                           ref List<string> sOIDs, ref List<string> sCheckInfos)
        {
            //���Դ���

            IPoint ipTestFromPoint = ipGriddingline.FromPoint;
            IPoint ipTestToPoint = ipGriddingline.ToPoint;

            double dFromTestX = ipTestFromPoint.X;
            double dFromTestY = ipTestFromPoint.Y;
            double dToTestX = ipTestToPoint.X;
            double dToTestY = ipTestToPoint.Y;
            try
            {
                //

                //ʹ�������߽��пռ��ѯ
                ISpatialFilter ipSpatialFilter = new SpatialFilterClass();

                IGeometry ipLineBufGeoInSide, ipLineBufGeoOutSide;

                ISelectionSet ipInSideSelectionSet = null;
                ISelectionSet ipOutSideSelectionSet = null;

                //��ȡ�ڻ�������Ҫ�ؼ�
                //IPolygon ipPolygon = LineBuffer(ipGriddingline,dblTolerance);
                IPolyline ipPolyline = LineBuffer(ipGriddingline, dblTolerance);

                ipLineBufGeoInSide = ipPolyline;

                ipSpatialFilter.Geometry = ipLineBufGeoInSide;
                ipSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
                ipSpatialFilter.WhereClause = szSql;

                ipInSideSelectionSet =
                    pMatchEdgeFeatureClass.Select(ipSpatialFilter, esriSelectionType.esriSelectionTypeHybrid,
                                                  esriSelectionOption.esriSelectionOptionNormal, null);
                int lInSideSelectionCount = ipInSideSelectionSet.Count;

                //�ڻ�����û�ж�����ô�⻺�����Ķ���Ҳ���ü��
                if (lInSideSelectionCount < 1)
                {
                    return true;
                }

                //��ȡ�⻺�������Ҫ�ؼ�
                ipPolyline = LineBuffer(ipGriddingline, -dblTolerance);
                ipLineBufGeoOutSide = ipPolyline;

                ipSpatialFilter.Geometry = (IGeometry) ipLineBufGeoOutSide;

                ipOutSideSelectionSet =
                    pMatchEdgeFeatureClass.Select(ipSpatialFilter, esriSelectionType.esriSelectionTypeHybrid,
                                                  esriSelectionOption.esriSelectionOptionNormal, null);

                int lOutSideSelectionCount = ipOutSideSelectionSet.Count;

                IScratchWorkspaceFactory ipSwf = new ScratchWorkspaceFactoryClass();
                IWorkspace ipScratchWorkspace = ipSwf.CreateNewScratchWorkspace();

                bool bIsInToOut = true; //�ͷ����ڵ���
                for (int k = 0; k < 2; k++)
                {
                    ISelectionSet ipSourceSelectionSet = null;
                    ISelectionSet ipTargetSelectionSet = null;
                    if (bIsInToOut)
                    {
                        ipSourceSelectionSet = ipInSideSelectionSet;
                        ipTargetSelectionSet = ipOutSideSelectionSet;
                    }
                    else
                    {
                        ipSourceSelectionSet = ipOutSideSelectionSet;
                        ipTargetSelectionSet = ipInSideSelectionSet;
                    }

                    //����ipSourceSelectionSet�е�Ҫ��(Buffer����)
                    //Ȼ����ipTargetSelectionSet��ȡ�����ཻ��Ҫ��
                    ICursor ipSourceCursor;
                    ipSourceSelectionSet.Search(null, false, out ipSourceCursor);
                    IRow ipSourceRow = ipSourceCursor.NextRow();
                    IFields ipMatchEdgeFields = pMatchEdgeFeatureClass.Fields;
                    IField ipMatchEdgeField;

                    int nProcessingFeature = 0;
                    string sProgressMessage;
                    while (ipSourceRow != null)
                    {
                        nProcessingFeature++;

                        //������֤�ֶεõ�ipSourceRow�Ķ�Ӧ�ֶ�ֵ
                        int nFieldIndex;
                        string sMatchEdgeWhereClause;
                        int nFieldCount = nFieldArray.Count;
                        esriFieldType eMatchEdgeFieldType;
                        string sMatchEdgeFieldValue;

                        //ipSourceRow��OID
                        int lSourceRowOID = ipSourceRow.OID;
                        string sSourceRowOID = lSourceRowOID.ToString();

                        //�������Բ�ѯ����
                        sMatchEdgeWhereClause = GetCondition(ipSourceRow, ipMatchEdgeFields, nFieldArray);

                        //�����������ж��Ƿ��пռ��ϵĽӱ߶�������У��ٽ�һ���ж��Ƿ������Խӱ�

                        IGeometry ipSourceGeometry = ((IFeature) ipSourceRow).Shape;

                        ISpatialFilter ipSourceSpatialFilter = new SpatialFilterClass();

                        ipSourceSpatialFilter.Geometry = ipSourceGeometry;
                        ipSourceSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;

                        ISelectionSet ipSourceSelectionSet1 =
                            ipTargetSelectionSet.Select(ipSourceSpatialFilter, esriSelectionType.esriSelectionTypeHybrid,
                                                        esriSelectionOption.esriSelectionOptionNormal,
                                                        ipScratchWorkspace);

                        int lSourceSelectionCount = ipSourceSelectionSet1.Count;

                        if (lSourceSelectionCount > 0)
                        {
                            //��ͼ�νӱ�
                            ipSourceSpatialFilter.WhereClause = sMatchEdgeWhereClause;

                            ISelectionSet ipSourceAttrSelectionSet1 =
                                ipSourceSelectionSet1.Select(ipSourceSpatialFilter,
                                                             esriSelectionType.esriSelectionTypeHybrid,
                                                             esriSelectionOption.esriSelectionOptionNormal,
                                                             ipScratchWorkspace);
                            int lSourceAttrSelectionCount = ipSourceAttrSelectionSet1.Count;

                            if (lSourceAttrSelectionCount > 0)
                            {
                                //�����Խӱ�
                                //�жϽӱ߶����Ƿ����һ��
                                ICursor ipSourceAttrCursor;
                                ipSourceAttrSelectionSet1.Search(null, false, out ipSourceAttrCursor);

                                IRow ipSourceAttrRow = ipSourceAttrCursor.NextRow();
                                int nSourceAttr = 0;
                                while (ipSourceAttrRow != null)
                                {
                                    int lSourceAttrOID = ipSourceAttrRow.OID;

                                    if (lSourceAttrOID != lSourceRowOID)
                                    {
                                        nSourceAttr++;
                                    }
                                    ipSourceAttrRow = ipSourceAttrCursor.NextRow();
                                }

                                string sInfo;
                                if (nSourceAttr > 1)
                                {
                                    sOIDs.Add(sSourceRowOID);
                                    sInfo = sSourceRowOID + "Ҫ�ش���" + nSourceAttr + "���ӱ߶���";
                                    sCheckInfos.Add(sInfo);
                                }
                            }
                            else
                            {
                                sOIDs.Add(sSourceRowOID);
                                //û�����Խӱ߶���
                                string sInfo = sSourceRowOID + "Ҫ���нӱ߶���,�����Բ�ͬ";
                                sCheckInfos.Add(sInfo);
                            }
                        }
                        else
                        {
                            sOIDs.Add(sSourceRowOID);
                            //û�нӱ߶���
                            string sInfo = sSourceRowOID + "Ҫ��ȱ�ٶ�Ӧ�Ľӱ߶���";
                            sCheckInfos.Add(sInfo);
                        }
                        Marshal.ReleaseComObject(ipSourceRow);
                        ipSourceRow = ipSourceCursor.NextRow();
                    }
                    bIsInToOut = false;
                }
                return true;
            }
            catch (Exception ex)
            {
                SendMessage(enumMessageType.Exception, ex.ToString());
                return false;
            }
        }