USGS-WiM / StreamStats

USGS StreamStats
https://streamstats.usgs.gov/ss/
Other
15 stars 7 forks source link

Move regulation to frontend #1009

Open kjacobsen16 opened 4 years ago

kjacobsen16 commented 4 years ago

query the dam points with the delineated basin and find the polygons for the associated points, pull data off of gis server

we should alert user after delineation if basin contains regulation points

jknewson commented 4 years ago

ok, found the files in my backup files from 2 machines ago. Built in 2015 (wow that was a long time ago)

Maplayer.FilterFeature -> called on line 115 of RegulationServiceAgent: -> used to mask the dam locations and identify which dams are nested. This is done by using the dam contributing areas.

MapLayer.cs

 public IFeatureClass FilterFeature(string whereclause, Boolean excludeNested = true) {
            QueryFilter pQFilter = null;
            IFeatureCursor pCursor = null;
            IFeature pFeature = null;
            IFeatureClass result = null;
            int i = 0;

            SpatialOps sOps = null;
            try
            {
               result = CreateEmptyFeatureClass();

                sOps = new SpatialOps(fClass);
                pQFilter = new QueryFilter();
                pQFilter.WhereClause = whereclause;

                pCursor = this.fClass.Search(pQFilter, true);
                //move to first feature
                while ((pFeature = pCursor.NextFeature()) != null)
                {
                    if (excludeNested && !sOps.IsNested(pFeature, whereclause))
                        Add2Feature(result, pFeature);
                }//next

                return result;
            }
            catch (Exception ex)
            {
                return null;
            }
            finally
            {
                //Local Cleanup
                if (pQFilter != null) { Marshal.FinalReleaseComObject(pQFilter); pQFilter = null; }
                if (pFeature != null) { Marshal.FinalReleaseComObject(pFeature); pFeature = null; }
                if (pCursor != null) { Marshal.FinalReleaseComObject(pCursor); pCursor = null; }

                //do not release
                result = null;
            }
        }

SpatialOps:

        public List<string> GetFeatureFields(IFeatureClass fclass, string fieldname, IGeometryBag mask = null) {
            ISpatialFilter spFilter = null;
            IFeature pFeature = null;
            IFeatureCursor pCursor = null;
            List<string> fieldList = new List<string>();
            Int32 fieldIndex = -1;
            try
            {
                fieldIndex = fclass.Fields.FindField(fieldname);
                if (fieldIndex < 0) throw new Exception("Feature does not include " + fieldname);
                if (mask != null) 
                {
                    this.mask = (IGeometry)mask;
                    this.setSpatialRef(this.mask);
                }
                spFilter = getSpatialFilter(esriSpatialRelEnum.esriSpatialRelIntersects);

                pCursor = fclass.Search(spFilter, true);
                while ((pFeature = pCursor.NextFeature()) != null)
                {
                    fieldList.Add(pFeature.Value[fieldIndex].ToString());
                }//next pFeature

                return fieldList;
            }
            catch (Exception ex)
            {
                throw;
            }
            finally
            {
                if (spFilter != null) { Marshal.FinalReleaseComObject(spFilter); spFilter = null; }
                if (pFeature != null) { Marshal.FinalReleaseComObject(pFeature); pFeature = null; }
                if (pCursor != null) { Marshal.FinalReleaseComObject(pCursor); pCursor = null; }
            }        
        }

        public Boolean IsNested(IFeature feature, string whereclause){
             ISpatialFilter spFilter = null;
            IFeature pFeature = null;
            IFeatureCursor pCursor = null;
            try
            {
                this.mask = (IGeometry)feature.Shape;
                this.setSpatialRef(this.mask);

                spFilter = getSpatialFilter(esriSpatialRelEnum.esriSpatialRelWithin);
                spFilter.WhereClause = whereclause;

                pCursor = fClass.Search(spFilter, true);
                while ((pFeature = pCursor.NextFeature()) != null)
                {
                    if (pFeature.OID == feature.OID) continue;
                    return true;
                }//next pFeature

                return false;
            }
            catch (Exception ex)
            {
                throw;
            }
            finally
            {
                if (spFilter != null) { Marshal.FinalReleaseComObject(spFilter); spFilter = null; }
                if (pFeature != null) { Marshal.FinalReleaseComObject(pFeature); pFeature = null; }
                if (pCursor != null) { Marshal.FinalReleaseComObject(pCursor); pCursor = null; }
            }
        }

RegulationRESTSOE.zip

kjacobsen16 commented 4 years ago

@jknewson I tried to run a Debug session using Visual Studio to make following the code easier, but I'm getting a lot of errors. The .csproj file opened up fine, but looks like it's not finding most dependencies or the WiMRestSOE file. Am I missing something, is it not something I should be able to run there? I am completely lost as far as c# goes. image

jknewson commented 4 years ago

SOE's are a different beast than any other type of project. There are ESRI addons / extenstions that need to be added and in order to debug, the SOE needs to be running (usually involves installing arcserver on your local machine, installing the soe to a mapservice, then attaching your IDE to the soe). It's something I haven't done for years, but I'm sure there is a document on the ESRI website.

Its a lot of overhead, if your not planning on pursuing. It's great, when it works, but more often than not, is a real pain.

kjacobsen16 commented 4 years ago

When this is done, we should address a couple issues: