Note: Forums will be making significant UX changes to address key usability improvements surrounding search, discoverability and navigation. To learn more about these changes please visit the announcement which can be found HERE.
C# Invalid SRID when inserting binary data

Answered C# Invalid SRID when inserting binary data

  • lunes, 09 de julio de 2012 15:13
     
      Tiene código

    Hello , 

    I'm trying to insert some polygons in my DB  using nHibernate and i have received the following error : 

    A .NET Framework error occurred during execution of user-defined routine or aggregate "geography": System.ArgumentException: 24204: The spatial reference identifier (SRID) is not valid. The specified SRID must match one of the supported SRIDs displayed in the sys.spatial_reference_systems catalog view. System.ArgumentException: at Microsoft.SqlServer.Types.SqlGeography.set_Srid(Int32 value) at Microsoft.SqlServer.Types.SqlGeography.Read(BinaryReader r) at SqlGeography::.DeserializeValidate(IntPtr , Int32 , CClrLobContext* ) . The statement has been terminated.

    but i have entered a SRID = 4326;

    I'm using a

    SqlGeographyBuilder();

    to build a polygon (rectangle) :

                        double left = Math.Min(NELng, SWLng);
                        double right = Math.Max(NELng, SWLng);
    
                        double bottom = Math.Min(NELat, SWLat);
                        double top = Math.Max(NELat, SWLat);
    
                        SqlGeographyBuilder builder = new SqlGeographyBuilder();
    
                        builder.SetSrid(LocationUtils.SRID);
                        builder.BeginGeography(OpenGisGeographyType.Polygon);
                     
                        builder.BeginFigure(top, left);
    
                        builder.AddLine(bottom, left);
                        builder.AddLine(bottom, right);
                        builder.AddLine(top, right);
                        builder.AddLine(top, left);
                        builder.EndFigure();
                        builder.EndGeography();

    what am I doing wrong ? 

Todas las respuestas

  • martes, 10 de julio de 2012 7:17
    Usuario que responde
     
     
    There's nothing I can see obviously wrong with your code... are you sure that LocationUtils.SRID is an int value 4326?

    twitter: @alastaira blog: http://alastaira.wordpress.com/

  • martes, 10 de julio de 2012 15:51
     
     

    My bad , i wasn't using NHibernate , but Linq2Sql .... 

    Can someone show me a sample on how to insert geo data with linq2sql or any other way ?

    Thanks! 

  • martes, 10 de julio de 2012 22:22
    Usuario que responde
     
     Respondida

    The latest version of the Entity Framework 5 (currently in Beta) is the only one to provide native support to spatial datatypes. But, these are only available if you're targetting a .NET 4.5 application. There's an example using LINQ at http://msdn.microsoft.com/en-us/hh859721

    If you're using an older version of Linq2SQL or targetting .NET <= 4.0 then you'll have to use a workaround, such as that described at http://blogs.u2u.be/diederik/post/2010/01/03/The-Missing-Linq-to-SQL-Spatial.aspx


    twitter: @alastaira blog: http://alastaira.wordpress.com/

    • Marcado como respuesta aviatrix viernes, 13 de julio de 2012 7:41
    •