public ShapeServiceFixture() { var serviceProvider = new ServiceCollection() .AddMemoryCache() .AddScoped <ShapefileDataReaderResolver>(serviceProvider => key => { ShapeAttributes shapeProperties = null; if (key == nameof(ShapeProperties.BoroughBoundaries)) { shapeProperties = ShapeProperties.BoroughBoundaries.GetAttribute <ShapeAttributes>(); } var options = serviceProvider.GetService <IOptions <ApplicationOptions> >(); var cache = serviceProvider.GetService <IMemoryCache>(); var shapeDirectory = $"{Path.Combine(options.Value.ShapeConfiguration.ShapeRootDirectory, shapeProperties.Directory, shapeProperties.FileName)}"; string shapePath = Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), shapeDirectory)); return(new CachedShapefileDataReader(cache, key, shapePath)); }) .AddScoped <BoroughBoundariesService>() .AddOptions() .Configure <ApplicationOptions>(Configuration) .AddSingleton(Configuration) .BuildServiceProvider(); BoroughBoundariesService = serviceProvider.GetRequiredService <BoroughBoundariesService>(); }
/** * Constructs a new surface quad with the specified normal (as opposed to highlight) attributes, the specified * center location and dimensions (in meters). Modifying the attribute reference after calling this constructor * causes this shape's appearance to change accordingly. * * @param normalAttrs the normal attributes. May be null, in which case default attributes are used. * @param center the quad's center location. * @param width the quad's width, in meters. * @param height the quad's height, in meters. * * @throws ArgumentException if the center is null, or if the width or height are negative. */ public SurfaceQuad(ShapeAttributes normalAttrs, LatLon center, double width, double height) { super(normalAttrs); if (center == null) { String message = Logging.getMessage("nullValue.CenterIsNull"); Logging.logger().severe(message); throw new ArgumentException(message); } if (width < 0) { String message = Logging.getMessage("Geom.WidthIsNegative", width); Logging.logger().severe(message); throw new ArgumentException(message); } if (height < 0) { String message = Logging.getMessage("Geom.HeightIsNegative", height); Logging.logger().severe(message); throw new ArgumentException(message); } this.center = center; this.width = width; this.height = height; }
public void preRender(KMLTraversalContext tc, DrawContext dc) { // If the attributes are not inline or internal then they might not be resolved until the external KML // document is resolved. Therefore check to see if resolution has occurred. if (this.isHighlighted()) { if (!this.highlightAttributesResolved) { ShapeAttributes a = this.getHighlightAttributes(); if (a == null || a.isUnresolved()) { a = this.makeAttributesCurrent(KMLConstants.HIGHLIGHT); if (a != null) { this.setHighlightAttributes(a); if (!a.isUnresolved()) { this.highlightAttributesResolved = true; } } } } } else { if (!this.normalAttributesResolved) { ShapeAttributes a = this.getAttributes(); if (a == null || a.isUnresolved()) { a = this.makeAttributesCurrent(KMLConstants.NORMAL); if (a != null) { this.setAttributes(a); if (!a.isUnresolved()) { this.normalAttributesResolved = true; } } } } } // Apply rotation the first time the polygon is rendered. This feature only applies to ground overlays with // position specified using a rotated LatLon box. if (this.mustApplyRotation) { this.applyRotation(dc); this.mustApplyRotation = false; } this.preRender(dc); }
/** * Constructs a new surface quad with the specified normal (as opposed to highlight) attributes, the specified * center location and dimensions (in meters). Modifying the attribute reference after calling this constructor * causes this shape's appearance to change accordingly. * * @param normalAttrs the normal attributes. May be null, in which case default attributes are used. * @param center the quad's center location. * @param width the quad's width, in meters. * @param height the quad's height, in meters. * @param heading the quad's heading, clockwise from North. * * @throws ArgumentException if the center or heading are null, or if the width or height are negative. */ public SurfaceQuad(ShapeAttributes normalAttrs, LatLon center, double width, double height, Angle heading) { this(normalAttrs, center, width, height); if (heading == null) { String message = Logging.getMessage("nullValue.HeadingIsNull"); Logging.logger().severe(message); throw new ArgumentException(message); } this.heading = heading; }
public void render(KMLTraversalContext tc, DrawContext dc) { // If the attributes are not inline or internal then they might not be resolved until the external KML // document is resolved. Therefore check to see if resolution has occurred. if (this.isHighlighted()) { if (!this.highlightAttributesResolved) { ShapeAttributes a = this.getCapHighlightAttributes(); if (a == null || a.isUnresolved()) { a = this.makeAttributesCurrent(KMLConstants.HIGHLIGHT); if (a != null) { this.setCapHighlightAttributes(a); this.setSideHighlightAttributes(a); if (!a.isUnresolved()) { this.highlightAttributesResolved = true; } } } } } else { if (!this.normalAttributesResolved) { ShapeAttributes a = this.getCapAttributes(); if (a == null || a.isUnresolved()) { a = this.makeAttributesCurrent(KMLConstants.NORMAL); if (a != null) { this.setCapAttributes(a); this.setSideAttributes(a); if (!a.isUnresolved()) { this.normalAttributesResolved = true; } } } } } this.render(dc); }
/** {@inheritDoc} */ public void copy(ShapeAttributes attributes) { if (attributes != null) { this.drawInterior = attributes.isDrawInterior(); this.drawOutline = attributes.isDrawOutline(); this.enableAntialiasing = attributes.isEnableAntialiasing(); this.enableLighting = attributes.isEnableLighting(); this.interiorMaterial = attributes.getInteriorMaterial(); this.outlineMaterial = attributes.getOutlineMaterial(); this.interiorOpacity = attributes.getInteriorOpacity(); this.outlineOpacity = attributes.getOutlineOpacity(); this.outlineWidth = attributes.getOutlineWidth(); this.outlineStippleFactor = attributes.getOutlineStippleFactor(); this.outlineStipplePattern = attributes.getOutlineStipplePattern(); this.imageSource = attributes.getImageSource(); this.imageScale = attributes.getImageScale(); } }
public static ShapeAttributes assembleInteriorAttributes(ShapeAttributes attrs, KMLPolyStyle style) { // Assign the attributes defined in the KML Feature element. if (style.getColor() != null) { Color color = WWUtil.decodeColorABGR(style.getColor()); attrs.setInteriorMaterial(new Material(color)); attrs.setInteriorOpacity((double)color.getAlpha() / 255); } if (style.getColorMode() != null && "random".Equals(style.getColorMode())) { attrs.setInteriorMaterial(new Material(WWUtil.makeRandomColor(attrs.getOutlineMaterial().getDiffuse()))); } return(attrs); }
public static ShapeAttributes assembleLineAttributes(ShapeAttributes attrs, KMLLineStyle style) { // Assign the attributes defined in the KML Feature element. if (style.getWidth() != null) { attrs.setOutlineWidth(style.getWidth()); } if (style.getColor() != null) { attrs.setOutlineMaterial(new Material(WWUtil.decodeColorABGR(style.getColor()))); } if (style.getColorMode() != null && "random".Equals(style.getColorMode())) { attrs.setOutlineMaterial(new Material(WWUtil.makeRandomColor(attrs.getOutlineMaterial().getDiffuse()))); } return(attrs); }
/** * Determine and set the {@link Path} highlight attributes from the KML <i>Feature</i> fields. * * @param attrType the type of attributes, either {@link KMLConstants#NORMAL} or {@link KMLConstants#HIGHLIGHT}. * * @return the new attributes. */ protected ShapeAttributes makeAttributesCurrent(String attrType) { ShapeAttributes attrs = this.getInitialAttributes( this.isHighlighted() ? KMLConstants.HIGHLIGHT : KMLConstants.NORMAL); // Get the KML sub-style for Line attributes. Map them to Shape attributes. KMLAbstractSubStyle lineSubStyle = this.parent.getSubStyle(new KMLLineStyle(null), attrType); if (!this.isHighlighted() || KMLUtil.isHighlightStyleState(lineSubStyle)) { KMLUtil.assembleLineAttributes(attrs, (KMLLineStyle)lineSubStyle); if (lineSubStyle.hasField(AVKey.UNRESOLVED)) { attrs.setUnresolved(true); } } // Get the KML sub-style for interior attributes. Map them to Shape attributes. KMLAbstractSubStyle fillSubStyle = this.parent.getSubStyle(new KMLPolyStyle(null), attrType); if (!this.isHighlighted() || KMLUtil.isHighlightStyleState(lineSubStyle)) { KMLUtil.assembleInteriorAttributes(attrs, (KMLPolyStyle)fillSubStyle); if (fillSubStyle.hasField(AVKey.UNRESOLVED)) { attrs.setUnresolved(true); } attrs.setDrawInterior(((KMLPolyStyle)fillSubStyle).isFill()); if (this.isExtrude()) { attrs.setDrawOutline(((KMLPolyStyle)fillSubStyle).isOutline()); } } return(attrs); }
/** * Creates a new <code>BasicShapeAttributes</code> configured with the specified <code>attributes</code>. * * @param attributes the attributes to configure the new <code>BasicShapeAttributes</code> with. * * @throws ArgumentException if <code>attributes</code> is <code>null</code>. */ public BasicShapeAttributes(ShapeAttributes attributes) { if (attributes == null) { String message = Logging.getMessage("nullValue.AttributesIsNull"); Logging.logger().severe(message); throw new ArgumentException(message); } this.drawInterior = attributes.isDrawInterior(); this.drawOutline = attributes.isDrawOutline(); this.enableAntialiasing = attributes.isEnableAntialiasing(); this.enableLighting = attributes.isEnableLighting(); this.interiorMaterial = attributes.getInteriorMaterial(); this.outlineMaterial = attributes.getOutlineMaterial(); this.interiorOpacity = attributes.getInteriorOpacity(); this.outlineOpacity = attributes.getOutlineOpacity(); this.outlineWidth = attributes.getOutlineWidth(); this.outlineStippleFactor = attributes.getOutlineStippleFactor(); this.outlineStipplePattern = attributes.getOutlineStipplePattern(); this.imageSource = attributes.getImageSource(); this.imageScale = attributes.getImageScale(); }
/** * Constructs a new surface quad with the specified normal (as opposed to highlight) attributes, default center * location, default dimensions, and default heading. Modifying the attribute reference after calling this * constructor causes this shape's appearance to change accordingly. * * @param normalAttrs the normal attributes. May be null, in which case default attributes are used. */ public SurfaceQuad(ShapeAttributes normalAttrs) { super(normalAttrs); }
/// <summary> /// Configure Services. /// </summary> /// <param name="services"></param> public void ConfigureServices(IServiceCollection services) { services.AddOptions(); services.Configure <ApplicationOptions>(Configuration); services.Configure <Common.Configuration.ApplicationOptions>(Configuration); services.AddSingleton(Configuration); services.AddMemoryCache(); services.AddSingleton <CronJobServiceHealthCheck>(); var config = Configuration.Get <ApplicationOptions>(); services.DisplayConfiguration(Configuration, HostingEnvironment); var commonConfig = Configuration.Get <MicroService.Common.Configuration.ApplicationOptions>(); services.AddCustomApiVersioning(); services.AddOpenTelemetryTracing( builder => { _ = builder .SetResourceBuilder(ResourceBuilder.CreateDefault() .AddService(HostingEnvironment.ApplicationName)) .AddSource(nameof(FeatureServiceController)) .AddAspNetCoreInstrumentation() .AddHttpClientInstrumentation(); if (commonConfig.JaegerConfiguration.Enabled) { builder.AddJaegerExporter(o => { o.AgentHost = commonConfig.JaegerConfiguration.Host; o.AgentPort = commonConfig.JaegerConfiguration.Port; }); } if (HostingEnvironment.IsDevelopment()) { builder.AddConsoleExporter(options => options.Targets = ConsoleExporterOutputTargets.Console); } }); var metrics = AppMetrics.CreateDefaultBuilder() .OutputMetrics .AsPrometheusPlainText() .Build(); MetricsHelpers.SetMetricsCustomTag(metrics, "OSDescription", System.Runtime.InteropServices.RuntimeInformation.OSDescription); MetricsHelpers.SetMetricsCustomTag(metrics, "instance", Dns.GetHostName()); metrics.Options.ReportingEnabled = true; services.AddMetrics(metrics); services.AddAppMetricsHealthPublishing(); services.AddAppMetricsCollectors(); services.AddTransient <IConfigureOptions <SwaggerGenOptions>, ConfigureSwaggerOptions>(); services.AddSwaggerConfiguration(); services.AddCorsConfiguration(); // Repositories services.AddScoped <ITestDataRepository>(x => new TestDataRepository(config.ConnectionStrings.PostgreSql)); // Services services.AddScoped <ICalculationService, CalculationService>(); services.AddScoped <ShapefileDataReaderResolver>(serviceProvider => key => { ShapeAttributes shapeProperties = null; if (key == nameof(ShapeProperties.BoroughBoundaries)) { shapeProperties = ShapeProperties.BoroughBoundaries.GetAttribute <ShapeAttributes>(); } else if (key == nameof(ShapeProperties.CommunityDistricts)) { shapeProperties = ShapeProperties.CommunityDistricts.GetAttribute <ShapeAttributes>(); } else if (key == nameof(ShapeProperties.DSNYDistricts)) { shapeProperties = ShapeProperties.DSNYDistricts.GetAttribute <ShapeAttributes>(); } else if (key == nameof(ShapeProperties.HistoricDistricts)) { shapeProperties = ShapeProperties.HistoricDistricts.GetAttribute <ShapeAttributes>(); } else if (key == nameof(ShapeProperties.Neighborhoods)) { shapeProperties = ShapeProperties.Neighborhoods.GetAttribute <ShapeAttributes>(); } else if (key == nameof(ShapeProperties.NeighborhoodTabulationAreas)) { shapeProperties = ShapeProperties.NeighborhoodTabulationAreas.GetAttribute <ShapeAttributes>(); } else if (key == nameof(ShapeProperties.NypdPolicePrecincts)) { shapeProperties = ShapeProperties.NypdPolicePrecincts.GetAttribute <ShapeAttributes>(); } else if (key == nameof(ShapeProperties.NypdSectors)) { shapeProperties = ShapeProperties.NypdSectors.GetAttribute <ShapeAttributes>(); } else if (key == nameof(ShapeProperties.NychaDevelopments)) { shapeProperties = ShapeProperties.NychaDevelopments.GetAttribute <ShapeAttributes>(); } else if (key == nameof(ShapeProperties.Parks)) { shapeProperties = ShapeProperties.Parks.GetAttribute <ShapeAttributes>(); } else if (key == nameof(ShapeProperties.Subway)) { shapeProperties = ShapeProperties.Subway.GetAttribute <ShapeAttributes>(); } else if (key == nameof(ShapeProperties.ZipCodes)) { shapeProperties = ShapeProperties.ZipCodes.GetAttribute <ShapeAttributes>(); } else { throw new KeyNotFoundException(key); } var options = serviceProvider.GetService <IOptions <ApplicationOptions> >(); var cache = serviceProvider.GetService <IMemoryCache>(); var rootDirectory = options?.Value?.ShapeConfiguration.ShapeSystemRootDirectory; string shapeFileNamePath = Path.Combine(rootDirectory, shapeProperties.Directory, shapeProperties.FileName); return(new CachedShapefileDataReader(cache, key, shapeFileNamePath)); }); // Feature Service Lookups services.AddScoped <BoroughBoundariesService>(); services.AddScoped <CommunityDistrictsService>(); services.AddScoped <DSNYDistrictsService>(); services.AddScoped <HistoricDistrictService>(); services.AddScoped <NeighborhoodsService <NeighborhoodShape> >(); services.AddScoped <NeighborhoodTabulationAreasService>(); services.AddScoped <NypdPolicePrecinctService>(); services.AddScoped <NypdSectorsService <NypdSectorShape> >(); services.AddScoped <NychaDevelopmentService <NychaDevelopmentShape> >(); services.AddScoped <ParkService <ParkShape> >(); services.AddScoped <SubwayService <SubwayShape> >(); services.AddScoped <ZipCodeService <ZipCodeShape> >(); services.AddScoped <ShapeServiceResolver>(serviceProvider => key => { return(key switch { nameof(ShapeProperties.BoroughBoundaries) => serviceProvider.GetService <BoroughBoundariesService>(), nameof(ShapeProperties.CommunityDistricts) => serviceProvider.GetService <CommunityDistrictsService>(), nameof(ShapeProperties.DSNYDistricts) => serviceProvider.GetService <DSNYDistrictsService>(), nameof(ShapeProperties.HistoricDistricts) => serviceProvider.GetService <HistoricDistrictService>(), nameof(ShapeProperties.Neighborhoods) => serviceProvider.GetService <NeighborhoodsService <NeighborhoodShape> >(), nameof(ShapeProperties.NeighborhoodTabulationAreas) => serviceProvider.GetService <NeighborhoodTabulationAreasService>(), nameof(ShapeProperties.NypdPolicePrecincts) => serviceProvider.GetService <NypdPolicePrecinctService>(), nameof(ShapeProperties.NypdSectors) => serviceProvider.GetService <NypdSectorsService <NypdSectorShape> >(), nameof(ShapeProperties.NychaDevelopments) => serviceProvider.GetService <NychaDevelopmentService <NychaDevelopmentShape> >(), nameof(ShapeProperties.Parks) => serviceProvider.GetService <ParkService <ParkShape> >(), nameof(ShapeProperties.Subway) => serviceProvider.GetService <SubwayService <SubwayShape> >(), nameof(ShapeProperties.ZipCodes) => serviceProvider.GetService <ZipCodeService <ZipCodeShape> >(), _ => throw new KeyNotFoundException(key) }); });
/** * Export ShapeAttributes as KML Pair element in a StyleMap. This method assumes that the StyleMap tag has already * been written; it writes the Pair tag. * * @param xmlWriter Writer to receive the Style element. * @param styleType The type of style: normal or highlight. Value should match either {@link KMLConstants#NORMAL} * or {@link KMLConstants#HIGHLIGHT} * @param attributes Attributes to export. The method takes no action if this parameter is null. * * @throws javax.xml.stream.XMLStreamException * if exception occurs writing XML. * @throws java.io.IOException if exception occurs exporting data. */ public static void exportAttributesAsKML(XMLStreamWriter xmlWriter, String styleType, ShapeAttributes attributes)