Skip to content

Commit

Permalink
Fix: Add Format String to avoid storing truncated location info
Browse files Browse the repository at this point in the history
  • Loading branch information
Georg Rollinger committed Jan 22, 2015
1 parent 8a0cf08 commit 42ec1c4
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions DiversityService/DiversityService.Upload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ public int InsertEvent(Event ev, IEnumerable<EventProperty> properties, UserCred
db.Insert(loc);

if (!string.IsNullOrWhiteSpace(geoString))
{
db.Execute("UPDATE [dbo].[CollectionEventLocalisation] SET geography=GEOGRAPHY::STGeomFromText(@0, 4326) WHERE CollectionEventID=@1 AND LocalisationSystemID=@2", geoString, loc.CollectionEventID, loc.LocalisationSystemID);
}
}

if (properties != null)
Expand All @@ -51,14 +53,12 @@ public int InsertEvent(Event ev, IEnumerable<EventProperty> properties, UserCred
db.Insert(p);
}


t.Complete();

return ev.CollectionEventID;
}
}


public int InsertSpecimen(Specimen s, UserCredentials login)
{
using (var db = login.GetConnection())
Expand All @@ -74,13 +74,11 @@ public int InsertSpecimen(Specimen s, UserCredentials login)
}
}


public int InsertIdentificationUnit(IdentificationUnit iu, IEnumerable<IdentificationUnitAnalysis> analyses, UserCredentials login)
{
using (var db = login.GetConnection())
using (var t = db.GetTransaction())
{

db.Insert(iu);
db.Insert(iu.GetIdentification(login));

Expand All @@ -106,7 +104,6 @@ public int InsertIdentificationUnit(IdentificationUnit iu, IEnumerable<Identific
}
}


public void InsertMMO(MultimediaObject mmo, UserCredentials login)
{
using (var db = login.GetConnection())
Expand All @@ -119,15 +116,18 @@ public void InsertMMO(MultimediaObject mmo, UserCredentials login)
CollectionEventSeriesImage cesi = mmo.ToSeriesImage();
db.Insert(cesi);
break;

case MultimediaOwner.Event:
CollectionEventImage cei = mmo.ToEventImage();
db.Insert(cei);
break;

case MultimediaOwner.Specimen:
case MultimediaOwner.IdentificationUnit:
CollectionSpecimenImage csi = mmo.ToSpecimenImage(db);
db.Insert(csi);
break;

default:
throw new ArgumentException("unknown type");
}
Expand All @@ -143,15 +143,15 @@ public void InsertMMO(MultimediaObject mmo, UserCredentials login)
private static string SerializeLocalizations(IEnumerable<Localization> locs)
{
// The points in the LineString must be unique
var uniqueLocs = (locs != null)
var uniqueLocs = (locs != null)
? locs.Distinct().ToList()
: new List<Localization>();

if (uniqueLocs.Count > 1)
{
var cult = new CultureInfo("en-US");
return string.Format("LINESTRING({0})",
string.Join(", ", uniqueLocs.Select(gp => string.Format(cult, "{0} {1}", gp.Longitude, gp.Latitude)))
string.Join(", ", uniqueLocs.Select(gp => string.Format(cult, "{0:R} {1:R}", gp.Longitude, gp.Latitude)))
);
}
else return string.Empty;
Expand All @@ -164,9 +164,9 @@ private static string SerializeLocalization(double? latitude, double? longitude,
return string.Empty;

var cult = new CultureInfo("en-US");
string longitudeStr = longitude.Value.ToString(cult);
string longitudeStr = longitude.Value.ToString("R", cult);

string latStr = latitude.Value.ToString(cult);
string latStr = latitude.Value.ToString("R", cult);
latStr = latStr.Replace(',', '.');

StringBuilder builder = new StringBuilder("POINT(");
Expand All @@ -175,7 +175,7 @@ private static string SerializeLocalization(double? latitude, double? longitude,
builder.Append(latStr);
if (altitude.HasValue && double.IsNaN((double)altitude) == false)
{
string altStr = altitude.Value.ToString(cult);
string altStr = altitude.Value.ToString("R", cult);
altStr = altStr.Replace(',', '.');
builder.Append(" ");
builder.Append(altStr);
Expand All @@ -185,4 +185,4 @@ private static string SerializeLocalization(double? latitude, double? longitude,
return builder.ToString();
}
}
}
}

0 comments on commit 42ec1c4

Please sign in to comment.