Spatial types performance

2 posts, 0 answers
  1. Валерий
    Валерий avatar
    1 posts
    Member since:
    Jul 2015

    Posted 14 Jul 2015 Link to this post

    I want to draw all geometry from database that instersects with specified rectangle with this code.

    But, is selects 1) Parcels that intersect in one query 2) Geometry of each parcel in other queries

    1) SELECT a.[Id] AS COL1, a.[CertificationDocId] AS COL2, a.[CertificationDocId] AS COL3, a.[Number] AS COL4 FROM [Parcels] a WHERE a.[Number] LIKE @p0 + '%' ESCAPE '\' AND a.[Geometry].STIntersects(@p1) = 1 ORDER BY COL1 

    2) SELECT [Geometry] AS COL1 FROM [Parcels] WHERE [Id] = @p0

     

    Can i use a single query somehow? 

     

    using (var quartersDb = new ProjectsByRegionsContext())
    {
    var parcels = quartersDb.Parcels
    .Where(p => p.Number.StartsWith(regionCode) && p.Geometry.STIsValid().ToString() == "1" && p.Geometry.STIntersects(sqlGeometry).Equals(1))
    .ToList();
    foreach (var parcel in parcels)
    {
    if (usedCadNumbers.Contains(parcel.Number))
    continue;
    usedCadNumbers.Add(parcel.Number);
    var drawedGeometry = CommandHelper.DrawGeometry(parcel.Geometry.ToNtsGeometry());
    BlockHelper.CreateBlock(parcel.Number, drawedGeometry, parcel.GetAttributes());
    }
    }

  2. Thomas
    Admin
    Thomas avatar
    590 posts

    Posted 16 Jul 2015 Link to this post

    Hi Valery,

    please have a look at http://docs.telerik.com/data-access/developers-guide/database-specifics/microsoft-sql-server/data-access-tasks-mssql-spatial-data .
    There it is described how to use spatial types with DataAccess. SqlGeometry and SqlGeography behave in similar ways, and you might be able to deduce the solution to your issue.
    One additional note: It might be needed / or just easier to use a piece of SQL in the LINQ directly. We support that too with 'SQL islands' that you can use to express your needs. Please see this article http://www.telerik.com/support/kb/data-access/details/using-full-text-search-features-with-linq-queries for more information. It can come handy when dealing with the results from the spatial methods.

    Please note also: Telerik Data Access supports only version 10.0 of the Microsoft.SqlServer.Types assembly. We do not test with the newer versions, but they might work fine with a bit of binding redirection.


    Regards,
    Thomas
    Telerik
     
    Check out the latest announcement about Telerik Data Access vNext as a powerful framework able to solve core development problems.
  3. DevCraft banner
Back to Top