예제 #1
0
        public static async Task <string> GenerateGeoJson(string geoJsonContent, string pageUrl)
        {
            var serializer = GeoJsonSerializer.Create(SpatialHelpers.Wgs84GeometryFactory());

            using var stringReader = new StringReader(geoJsonContent);
            using var jsonReader   = new JsonTextReader(stringReader);
            var contentFeatureCollection = serializer.Deserialize <FeatureCollection>(jsonReader);

            var bounds = SpatialConverters.GeometryBoundingBox(SpatialConverters.GeoJsonToGeometries(geoJsonContent));

            var jsonDto = new GeoJsonSiteJsonData(pageUrl,
                                                  new SpatialBounds(bounds.MaxY, bounds.MaxX, bounds.MinY, bounds.MinX), contentFeatureCollection);

            await using var stringWriter = new StringWriter();
            using var jsonWriter         = new JsonTextWriter(stringWriter);
            serializer.Serialize(jsonWriter, jsonDto);

            return(stringWriter.ToString());
        }
예제 #2
0
        public static async Task <GenerationReturn> Validate(LineContent lineContent)
        {
            var rootDirectoryCheck = UserSettingsUtilities.ValidateLocalSiteRootDirectory();

            if (!rootDirectoryCheck.Item1)
            {
                return(await GenerationReturn.Error($"Problem with Root Directory: {rootDirectoryCheck.Item2}",
                                                    lineContent.ContentId));
            }

            var commonContentCheck = await CommonContentValidation.ValidateContentCommon(lineContent);

            if (!commonContentCheck.valid)
            {
                return(await GenerationReturn.Error(commonContentCheck.explanation, lineContent.ContentId));
            }

            var updateFormatCheck = CommonContentValidation.ValidateUpdateContentFormat(lineContent.UpdateNotesFormat);

            if (!updateFormatCheck.isValid)
            {
                return(await GenerationReturn.Error(updateFormatCheck.explanation, lineContent.ContentId));
            }

            try
            {
                var serializer = GeoJsonSerializer.Create(SpatialHelpers.Wgs84GeometryFactory(), 3);

                using var stringReader = new StringReader(lineContent.Line);
                using var jsonReader   = new JsonTextReader(stringReader);
                var featureCollection = serializer.Deserialize <FeatureCollection>(jsonReader);
                if (featureCollection.Count < 1)
                {
                    return(await GenerationReturn.Error(
                               "The GeoJson for the line appears to have an empty Feature Collection?", lineContent.ContentId));
                }
                if (featureCollection.Count > 1)
                {
                    return(await GenerationReturn.Error(
                               "The GeoJson for the line appears to contain multiple elements? It should only contain 1 line...",
                               lineContent.ContentId));
                }
                if (featureCollection[0].Geometry is not LineString)
                {
                    return(await GenerationReturn.Error(
                               "The GeoJson for the line has one element but it isn't a LineString?", lineContent.ContentId));
                }
                var lineString = featureCollection[0].Geometry as LineString;
                if (lineString == null || lineString.Count < 1 || lineString.Length == 0)
                {
                    return(await GenerationReturn.Error("The LineString doesn't have any points or is zero length?",
                                                        lineContent.ContentId));
                }
            }
            catch (Exception e)
            {
                return(await GenerationReturn.Error(
                           $"Error parsing the FeatureCollection and/or problems checking the LineString {e.Message}",
                           lineContent.ContentId));
            }

            return(await GenerationReturn.Success("Line Content Validation Successful"));
        }