Beispiel #1
0
        public static DateTime GetLastLoadDate()
        {
            DateTime lastLoadDate;

            Uri lastLoadDateUrl = new Uri(FirmaWebConfiguration.LastLoadDateUrl);

            try
            {
                using (var webClient = new WebClient())
                {
                    string response         = webClient.DownloadString(lastLoadDateUrl);
                    var    lastLoadDateJson = JsonTools.DeserializeObject <LastLoadDateJsonResponse>(response);
                    lastLoadDate = lastLoadDateJson.LoadCompleteDt;
                }
            }
            catch (Exception exception)
            {
                var logger = LogManager.GetLogger(typeof(FinanceApiLastLoadUtil));

                string errorMessage = $"Error retrieving URL {lastLoadDateUrl}: {exception.Message}";
                logger.Error(errorMessage);
                throw;
            }

            return(lastLoadDate);
        }
        public JsonResult SaveGridSettings()
        {
            var gridTable             = JsonTools.DeserializeObject <GridTable>(Request.Form["Data"]);
            var gridSettingsViewModel = new GridSettingsViewModel(gridTable);

            gridSettingsViewModel.Save(CurrentFirmaSession);
            return(new JsonResult());
        }
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            var errors = new List <ValidationResult>();

            FileResource.ValidateFileSize(FileResourceData, errors, GeneralUtility.NameOf(() => FileResourceData));

            using (var disposableTempFile = DisposableTempFile.MakeDisposableTempFileEndingIn(".gdb.zip"))
            {
                var gdbFile = disposableTempFile.FileInfo;
                FileResourceData.SaveAs(gdbFile.FullName);

                var ogr2OgrCommandLineRunner = new Ogr2OgrCommandLineRunner(FirmaWebConfiguration.Ogr2OgrExecutable,
                                                                            Ogr2OgrCommandLineRunner.DefaultCoordinateSystemId,
                                                                            FirmaWebConfiguration.HttpRuntimeExecutionTimeout.TotalMilliseconds);

                List <string> featureClassNames = null;
                try
                {
                    featureClassNames = OgrInfoCommandLineRunner.GetFeatureClassNamesFromFileGdb(new FileInfo(FirmaWebConfiguration.OgrInfoExecutable),
                                                                                                 gdbFile,
                                                                                                 Ogr2OgrCommandLineRunner.DefaultTimeOut);
                }
                catch (Exception e)
                {
                    errors.Add(new ValidationResult("There was a problem uploading your file geodatabase. Verify it meets the requirements and is not corrupt."));
                    SitkaLogger.Instance.LogDetailedErrorMessage(e);
                }

                if (featureClassNames != null)
                {
                    var featureClasses = featureClassNames.ToDictionary(x => x,
                                                                        x =>
                    {
                        try
                        {
                            var geoJson = ogr2OgrCommandLineRunner.ImportFileGdbToGeoJson(gdbFile, x, false);
                            return(JsonTools.DeserializeObject <FeatureCollection>(geoJson));
                        }
                        catch (Exception e)
                        {
                            errors.Add(new ValidationResult($"There was a problem processing the Feature Class \"{x}\"."));
                            SitkaLogger.Instance.LogDetailedErrorMessage(e);
                            return(null);
                        }
                    }).Where(x => x.Value != null && FocusAreaLocationStaging.IsUsableFeatureCollectionGeoJson(x.Value));

                    if (!featureClasses.Any())
                    {
                        errors.Add(new ValidationResult("There are no usable Feature Classes in the uploaded file. Feature Classes must contain Polygon and/or Multi-Polygon features."));
                    }
                }
            }

            return(errors);
        }
Beispiel #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="gisFile"></param>
        /// <param name="originalFilename">This is the original name of the file as it appeared on the users file system. It is provided just for error messaging purposes.</param>
        /// <param name="organization"></param>
        /// <returns></returns>
        public static List <OrganizationBoundaryStaging> CreateOrganizationBoundaryStagingStagingListFromGdb(FileInfo gisFile, string originalFilename, Organization organization)
        {
            var ogr2OgrCommandLineRunner = new Ogr2OgrCommandLineRunner(FirmaWebConfiguration.Ogr2OgrExecutable,
                                                                        LtInfoGeometryConfiguration.DefaultCoordinateSystemId,
                                                                        FirmaWebConfiguration.HttpRuntimeExecutionTimeout.TotalMilliseconds);

            var geoJsons =
                OgrInfoCommandLineRunner.GetFeatureClassNamesFromFileGdb(new FileInfo(FirmaWebConfiguration.OgrInfoExecutable), gisFile, originalFilename, Ogr2OgrCommandLineRunner.DefaultTimeOut)
                .ToDictionary(x => x, x => ogr2OgrCommandLineRunner.ImportFileGdbToGeoJson(gisFile, x, false))
                .Where(x => OrganizationBoundaryStaging.IsUsableFeatureCollectionGeoJson(JsonTools.DeserializeObject <FeatureCollection>(x.Value)))
                .ToDictionary(x => x.Key, x => new FeatureCollection(JsonTools.DeserializeObject <FeatureCollection>(x.Value).Features.Where(OrganizationBoundaryStaging.IsUsableFeatureGeoJson).ToList()).ToGeoJsonString());

            Check.Assert(geoJsons.Count != 0, "Number of usable Feature Classes in uploaded file must be greater than 0.");

            return(geoJsons.Select(x => new OrganizationBoundaryStaging(organization, x.Key, x.Value)).ToList());
        }
Beispiel #5
0
        public void CanReadColumnNamesFromGeoJsonString()
        {
            var          gdbFileInfo     = FileUtility.FirstMatchingFileUpDirectoryTree(@"LTInfo.Common\GdalOgr\SampleFileGeodatabase.gdb.zip");
            const string sourceLayerName = "MySampleFeatureClass";

            // Act
            // ---
            const int    totalMilliseconds        = 110000;
            const string pathToOgr2OgrExecutable  = @"C:\Program Files\GDAL\ogr2ogr.exe";
            var          ogr2OgrCommandLineRunner = new Ogr2OgrCommandLineRunner(pathToOgr2OgrExecutable, GdalGeoJsonTest.CoordinateSystemId, totalMilliseconds);
            var          geoJson = ogr2OgrCommandLineRunner.ImportFileGdbToGeoJson(gdbFileInfo, sourceLayerName, true);


            var a          = JsonTools.DeserializeObject <GeoJSON.Net.Feature.FeatureCollection>(geoJson);
            var columnList = new List <string> {
                "Ogr_Fid", "Ogr_Geometry", "MyIntColumn", "MyStringColumn", "MyFloatColumn"
            };
        }
Beispiel #6
0
        public void CanReadColumnNamesFromGeoJsonString()
        {
            // Arrange
            // -------
            var          gdbFileInfo              = FileUtility.FirstMatchingFileUpDirectoryTree(@"LTInfo.Common\GdalOgr\SampleFileGeodatabase.gdb.zip");
            const string sourceLayerName          = "MySampleFeatureClass";
            const int    totalMilliseconds        = 110000;
            const string pathToOgr2OgrExecutable  = @"C:\Program Files\GDAL\ogr2ogr.exe";
            var          ogr2OgrCommandLineRunner = new Ogr2OgrCommandLineRunner(pathToOgr2OgrExecutable, LtInfoGeometryConfiguration.DefaultCoordinateSystemId, totalMilliseconds);

            // Act
            // ---
            var geoJson = ogr2OgrCommandLineRunner.ImportFileGdbToGeoJson(gdbFileInfo, sourceLayerName, true);

            // Assert
            // ------
            var featureCollection     = JsonTools.DeserializeObject <GeoJSON.Net.Feature.FeatureCollection>(geoJson);
            var propertyNames         = featureCollection.Features.First().Properties.Select(x => x.Key).ToList();
            var expectedPropertyNames = new List <string> {
                "MyStringColumn", "IgnoredTextColumn", "IgnoredIntColumn", "MyIntColumn", "MyFloatColumn", "Shape_Length", "Shape_Area"
            };

            Assert.That(propertyNames, Is.EquivalentTo(expectedPropertyNames), "Should get expected columns");
        }
 public FeatureCollection ToGeoJsonFeatureCollection()
 {
     return JsonTools.DeserializeObject<FeatureCollection>(GeoJson);
 }
Beispiel #8
0
 public SimpleResponse(IRestResponse response) : base(response)
 {
     Data = JsonTools <T> .DeserializeObject("data", JObject.Parse(response.Content));
 }
        public FeatureCollection ToGeoJsonFeatureCollection()
        {
            var featureCollection = JsonTools.DeserializeObject <FeatureCollection>(GeoJson);

            return(featureCollection);
        }