Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7557263
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T12:05:15+00:00 2026-05-30T12:05:15+00:00

In SQL Server 2008 I have: Declare @pointIn geometry Declare @pointOut geometry Declare @polygon

  • 0

In SQL Server 2008 I have:

Declare @pointIn geometry
Declare @pointOut geometry
Declare @polygon geometry

SET @polygon = geometry::STGeomFromText('POLYGON((40 -9,40 -6,35 -6,35 -9,40 -9))', 4326)
SET @pointIn =  geometry::STGeomFromText('POINT (39 -8)', 4326)
SET @pointOut =  geometry::STGeomFromText('POINT (41 -3)', 4326)

select @polygon.STIntersects(@pointIn)
select @polygon.STIntersects(@pointOut)

And as expected I get results 1 and 0.

Now I am trying to bring the same code to C# using the library: Microsoft.SqlServer.Types.dll

Using the following code:

var p1lat = 40;
var p1long = -9;
var p2lat = 40;
var p2ong = -6;
var p3lat = 35;
var p3ong = -6;
var p4lat = 35;
var p4ong = -9;

var pILat = 39;
var pILong = -8;
var pOLat = 41;
var pOLong = -3;

System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");
const string polygonFormat = "POLYGON(({0} {1},{2} {3},{4} {5},{6} {7},{0} {1}))";
var polygon = string.Format(polygonFormat, p1lat, p1long, p2lat, p2ong, p3lat, p3ong, p4lat, p4ong);
var geometryString = new SqlChars(new SqlString(polygon));
var area = SqlGeography.STPolyFromText(geometryString, 4326);
var pointIn = SqlGeography.Point(pILat, pILong, 4326);
var pointOut = SqlGeography.Point(pOLat, pOLong, 4326);

Console.WriteLine(area.STIntersects(pointIn));
Console.WriteLine(area.STIntersects(pointOut));

I always get False, False….. and it should be True, False

Could someone help in here?

Thank you

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T12:05:16+00:00Added an answer on May 30, 2026 at 12:05 pm

    SqlGeography.Point and SqlGeography.STPointFromText use different coordinate order. Try one of the following solutions to fix the issue:

    • Swap coordinates in SqlGeography.Point method call;
    • Create points using WKT syntax (SqlGeography.STPointFromText).
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a query like this on Sql Server 2008: DECLARE @START_DATE DATETIME SET
In sql server 2008, I have the following query: select c.title as categorytitle, s.title
Sql server 2008 R2 I have two queries DECLARE @title NVARCHAR(500) = 'Finite AND
I am using SQL Server 2008 Enterprise. I have tried that if I set
I have lots of Polygons of datatype Geometry in SQL Server 2008. The image
On SQL Server 2008 R2, I have following T-SQL code: SELECT CAST(GETDATE() AS DATETIMEOFFSET);
Does SQL Server 2008 have a a data-type like MySQL's enum ?
In SQL Server 2008: I have two tables, dtlScheme and dtlRenewal, with a one
In SQL Server 2008: I have one table, and I want to do something
On my SQL Server 2008 I have a stored procedure with a large number

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.