Skip to content

Commit

Permalink
no warinings
Browse files Browse the repository at this point in the history
  • Loading branch information
emmanuelmathot committed Feb 8, 2023
1 parent d47db36 commit da591b0
Show file tree
Hide file tree
Showing 16 changed files with 235 additions and 86 deletions.
1 change: 1 addition & 0 deletions src/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,7 @@ dotnet_diagnostic.SA1111.severity = warning # Closing parenthesis should be
dotnet_diagnostic.SA1115.severity = warning # Parameter should follow comma
dotnet_diagnostic.SA1116.severity = warning # Split parameters should start on line after declaration
dotnet_diagnostic.SA1119.severity = warning # Statement must not use unnecessary parenthesis
dotnet_diagnostic.SA1122.severity = warning # Use string.Empty for empty strings
dotnet_diagnostic.SA1124.severity = warning # Do not use regions
dotnet_diagnostic.SA1127.severity = warning # Generic type constraints must be on their own line or share line with previous
dotnet_diagnostic.SA1128.severity = warning # Put constructor initializers on their own line
Expand Down
2 changes: 1 addition & 1 deletion src/DotNetStac.Test/StacLink/StacLinkTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public void CreateHelpers()
var stacLink = StacLink.CreateItemLink(new Uri("file:///test"), "text/plain");
stacLink.Title = "test";
var cloned = new StacLink(stacLink);
cloned = stacLink.Clone();
cloned = stacLink.Clone() as StacLink;
}
}
}
4 changes: 4 additions & 0 deletions src/DotNetStac/Schemas/StacSchemaResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ public StacSchemaResolver(JSchemaResolver jsonSchemaResolver)
/// <summary>
/// Loads the schema from url or shortcut.
/// </summary>
/// <param name="baseUrl">Base url.</param>
/// <param name="version">Version.</param>
/// <param name="shortcut">Shortcut.</param>
/// <returns>The schema.</returns>
public JSchema LoadSchema(string baseUrl = null, string version = null, string shortcut = null)
{
string vversion = string.IsNullOrEmpty(version) ? "unversioned" : "v" + version;
Expand Down
18 changes: 9 additions & 9 deletions src/DotNetStac/Schemas/StacValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public StacValidator(JSchemaUrlResolver jsonSchemaUrlResolver)
/// <summary>
/// Validate a json string against its STAC schema specification
/// </summary>
/// <param name="jsonstr"></param>
/// <param name="jsonstr">json string</param>
/// <returns>true when valid</returns>
public bool ValidateJson(string jsonstr)
{
Expand Down Expand Up @@ -121,15 +121,15 @@ private bool DetectDuplicateKeys(JsonReader jobject)
return true;
}

private bool ValidateJObject(JObject jObject)
private bool ValidateJObject(JObject jsonObject)
{
Type stacType = Utils.IdentifyStacType(jObject);
Type stacType = Utils.IdentifyStacType(jsonObject);

// Get all schema to validate against
List<string> schemas = new List<string>() { this._stacTypes[stacType] };
if (jObject.Value<JArray>("stac_extensions") != null)
if (jsonObject.Value<JArray>("stac_extensions") != null)
{
schemas.AddRange(jObject.Value<JArray>("stac_extensions").Select(a => a.Value<string>()));
schemas.AddRange(jsonObject.Value<JArray>("stac_extensions").Select(a => a.Value<string>()));
}

foreach (var schema in schemas)
Expand All @@ -144,19 +144,19 @@ private bool ValidateJObject(JObject jObject)
shortcut = schema;
}

if (!jObject.ContainsKey("stac_version"))
if (!jsonObject.ContainsKey("stac_version"))
{
throw new InvalidStacDataException("Missing 'stac_version' property");
}

var jsonSchema = this._schemaResolver.LoadSchema(baseUrl: baseUrl, shortcut: shortcut, version: jObject["stac_version"].Value<string>());
if (jObject.IsValid(jsonSchema, out IList<ValidationError> errorMessages))
var jsonSchema = this._schemaResolver.LoadSchema(baseUrl: baseUrl, shortcut: shortcut, version: jsonObject["stac_version"].Value<string>());
if (jsonObject.IsValid(jsonSchema, out IList<ValidationError> errorMessages))
{
continue;
}

throw new InvalidStacDataException(schema + ":\n" + string.Join("\n", errorMessages.
Select(e => FormatMessage(e, ""))));
Select(e => FormatMessage(e, string.Empty))));
}

return true;
Expand Down
3 changes: 3 additions & 0 deletions src/DotNetStac/SimpleLinksCollectionObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

namespace Stac
{
/// <summary>
/// A simple implementation of <see cref="ILinksCollectionObject"/> that can be used as a base class for other objects.
/// </summary>
public class SimpleLinksCollectionObject : ILinksCollectionObject
{
/// <summary>
Expand Down
6 changes: 3 additions & 3 deletions src/DotNetStac/StacAccessorsHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public static object GetProperty(this IStacPropertiesContainer propertiesContain
/// Gets the property.
/// </summary>
/// <typeparam name="T">the type of the property</typeparam>
/// <param name="propertiesContainer"></param>
/// <param name="propertiesContainer">The stac properties container.</param>
/// <param name="key">The key.</param>
/// <returns>the property value</returns>
public static T GetProperty<T>(this IStacPropertiesContainer propertiesContainer, string key)
Expand Down Expand Up @@ -177,7 +177,7 @@ public static T ChangeType<T>(object value)
/// <summary>
/// Removes the property.
/// </summary>
/// <param name="propertiesContainer"></param>
/// <param name="propertiesContainer">The stac properties container.</param>
/// <param name="key">The key.</param>
public static void RemoveProperty(this IStacPropertiesContainer propertiesContainer, string key)
{
Expand Down Expand Up @@ -237,7 +237,7 @@ public static void SetCollection(this StacItem stacItem, string collectionId, Ur
/// <summary>
/// Gets the collection of the Item as a StacLink
/// </summary>
/// <param name="stacItem"></param>
/// <param name="stacItem">The stac item.</param>
/// <returns>a Stac Link</returns>
public static StacLink GetCollection(this StacItem stacItem)
{
Expand Down
4 changes: 1 addition & 3 deletions src/DotNetStac/StacCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -302,9 +302,7 @@ public void Update(IDictionary<Uri, StacItem> items)
return;
}

/// <summary>
/// Clone this object.
/// </summary>
/// <inheritdoc/>
public object Clone()
{
return new StacCollection(this);
Expand Down
33 changes: 26 additions & 7 deletions src/DotNetStac/StacConvert.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,15 @@ public static class StacConvert
Culture = CultureInfo.CreateSpecificCulture("en-US"),
};

public static T Deserialize<T>(string json, JsonSerializerSettings serializerSettings = null)
where T : IStacObject
/// <summary>
/// Deserialize a STAC object from a JSON string.
/// </summary>
/// <typeparam name="T">The type of the STAC object to deserialize.</typeparam>
/// <param name="json">The JSON string to deserialize.</param>
/// <param name="serializerSettings">The JSON serializer settings to use.</param>
/// <returns>The deserialized STAC object.</returns>
public static T Deserialize<T>(string json, JsonSerializerSettings serializerSettings = null)
where T : IStacObject
{
// if (typeof(T) == typeof(StacItem)
// || typeof(T) == typeof(StacCollection)
Expand All @@ -33,15 +40,15 @@ public static T Deserialize<T>(string json, JsonSerializerSettings serializerSet
{
serializerSettings = DefaultJsonSerializerSettings;
}


serializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Utc;
JObject jobject = JsonConvert.DeserializeObject<JObject>(json, serializerSettings);
Type stacType = Utils.IdentifyStacType(jobject);
if (typeof(T) == typeof(IStacCatalog) && !typeof(IStacCatalog).IsAssignableFrom(stacType))
{
throw new InvalidCastException(stacType + "is not IStacCatalog");
}


try
{
// return (T)JsonConvert.DeserializeObject(json, typeof(T), serializerSettings);
Expand All @@ -53,19 +60,31 @@ public static T Deserialize<T>(string json, JsonSerializerSettings serializerSet
}
}

/// <summary>
/// Serialize a STAC object to a JSON string.
/// </summary>
/// <param name="stacObject">The STAC object to serialize.</param>
/// <param name="serializerSettings">The JSON serializer settings to use.</param>
/// <returns>The serialized JSON string.</returns>
public static string Serialize(IStacObject stacObject, JsonSerializerSettings serializerSettings = null)
{
if (serializerSettings == null)
{
serializerSettings = DefaultJsonSerializerSettings;
}


serializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Utc;
return JsonConvert.SerializeObject(stacObject, serializerSettings);
}

public static T Deserialize<T>(Stream stream)
where T : IStacObject
/// <summary>
/// Deserialize a STAC object from a JSON stream.
/// </summary>
/// <typeparam name="T">The type of the STAC object to deserialize.</typeparam>
/// <param name="stream">The JSON stream to deserialize.</param>
/// <returns>The deserialized STAC object.</returns>
public static T Deserialize<T>(Stream stream)
where T : IStacObject
{
StreamReader sr = new StreamReader(stream);
return Deserialize<T>(sr.ReadToEnd());
Expand Down
10 changes: 7 additions & 3 deletions src/DotNetStac/StacGeometryHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public static class StacGeometryHelpers
/// Get The bounding box of a geometry in a StacItem
/// </summary>
/// <param name="stacItem">The STAC Item containing the geometry</param>
/// <returns>The bounding box</returns>
public static double[] GetBoundingBoxFromGeometryExtent(this StacItem stacItem)
{
var boundingBoxes = stacItem.Geometry?.GetBoundingBox();
Expand All @@ -28,15 +29,15 @@ public static double[] GetBoundingBoxFromGeometryExtent(this StacItem stacItem)

if (boundingBoxes[0].Altitude.HasValue)
{
return new double[]
return new double[]
{
boundingBoxes[0].Longitude, boundingBoxes[0].Latitude, boundingBoxes[0].Altitude.Value,
boundingBoxes[1].Longitude, boundingBoxes[1].Latitude, boundingBoxes[1].Altitude.Value,
};
}
else
{
return new double[]
return new double[]
{
boundingBoxes[0].Longitude, boundingBoxes[0].Latitude,
boundingBoxes[1].Longitude, boundingBoxes[1].Latitude,
Expand All @@ -48,6 +49,7 @@ public static double[] GetBoundingBoxFromGeometryExtent(this StacItem stacItem)
/// Get the bounding box of a geometry object
/// </summary>
/// <param name="geometry">the geometry object</param>
/// <returns>The bounding box</returns>
public static IPosition[] GetBoundingBox(this IGeometryObject geometry)
{
if (geometry == null)
Expand Down Expand Up @@ -123,6 +125,7 @@ public static IPosition[] GetBoundingBox(this IGeometryObject geometry)
/// Get the lower left corner of a bounding box
/// </summary>
/// <param name="positions">set of positions</param>
/// <returns>the lower left corner</returns>
public static IPosition GetLowerLeft(this IPosition[] positions)
{
if (positions == null || positions.Length == 0)
Expand All @@ -144,13 +147,14 @@ public static IPosition GetLowerLeft(this IPosition[] positions)
/// Get the upper right corner of a bounding box.
/// </summary>
/// <param name="positions">set of positions.</param>
/// <returns>the upper right corner.</returns>
public static IPosition GetUpperRight(this IPosition[] positions)
{
if (positions == null || positions.Length == 0)
{
return null;
}


if (positions[0].Altitude.HasValue)
{
return new Position(positions.Max(p => p.Latitude), positions.Max(p => p.Longitude), positions.Max(p => p.Altitude));
Expand Down
38 changes: 32 additions & 6 deletions src/DotNetStac/StacItem.CommonMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ public string Title
set => this.SetProperty("title", value);
}

/// <summary>
/// Gets or sets the description of the Item.
/// </summary>
[JsonProperty("__description", Required = Required.Default)]
[JsonIgnore]
public string Description
Expand All @@ -31,6 +34,9 @@ public string Description
set => this.SetProperty("description", value);
}

/// <summary>
/// Gets or sets the license of the Item.
/// </summary>
public string License
{
get => this.GetProperty<string>("license");
Expand All @@ -41,36 +47,47 @@ public string License
/// Gets a list of providers, which may include all organizations capturing or processing the data or the hosting provider.
/// Providers should be listed in chronological order with the most recent provider being the last element of the list.
/// </summary>
/// <value>
/// A list of providers, which may include all organizations capturing or processing the data or the hosting provider.
/// Providers should be listed in chronological order with the most recent provider being the last element of the list.
/// </value>
public Collection<StacProvider> Providers => this.GetObservableCollectionProperty<StacProvider>("providers");

/// <summary>
/// Gets or sets the platform the data was acquired from.
/// </summary>
public string Platform
{
get => this.GetProperty<string>("platform");
set => this.SetProperty("platform", value);
}

/// <summary>
/// Gets or sets the instruments used to acquire the data.
/// </summary>
public IEnumerable<string> Instruments
{
get => this.GetProperty<string[]>("instruments");
set => this.SetProperty("instruments", value);
}

/// <summary>
/// Gets or sets the constellation the data was acquired from.
/// </summary>
public string Constellation
{
get => this.GetProperty<string>("constellation");
set => this.SetProperty("constellation", value);
}

/// <summary>
/// Gets or sets the mission the data was acquired from.
/// </summary>
public string Mission
{
get => this.GetProperty<string>("mission");
set => this.SetProperty("mission", value);
}

/// <summary>
/// Gets or sets the name of the satellite the data was acquired from.
/// </summary>
public double? Gsd
{
get => this.GetProperty<double>("gsd");
Expand All @@ -87,18 +104,27 @@ public double? Gsd
}
}

/// <summary>
/// Gets or sets the created date and time of the Item.
/// </summary>
public DateTime Created
{
get => this.GetProperty<DateTime>("created");
set => this.SetProperty("created", value);
}

/// <summary>
/// Gets or sets the updated date and time of the Item.
/// </summary>
public DateTime Updated
{
get => this.GetProperty<DateTime>("updated");
set => this.SetProperty("updated", value);
}

/// <summary>
/// Gets or sets the date and time the data was acquired.
/// </summary>
public Itenso.TimePeriod.ITimePeriod DateTime
{
get
Expand Down Expand Up @@ -127,7 +153,7 @@ public Itenso.TimePeriod.ITimePeriod DateTime
{
if (this.Properties["start_datetime"] is DateTime? && this.Properties["end_datetime"] is DateTime?)
{
return new Itenso.TimePeriod.TimeInterval(
return new Itenso.TimePeriod.TimeInterval(
(DateTime)this.Properties["start_datetime"],
(DateTime)this.Properties["end_datetime"]);
}
Expand All @@ -139,7 +165,7 @@ public Itenso.TimePeriod.ITimePeriod DateTime

return Itenso.TimePeriod.TimeInterval.Anytime;
}


set
{
// datetime, start_datetime, end_datetime
Expand Down
Loading

0 comments on commit da591b0

Please sign in to comment.