There are a number of issues with your SQL statement, so let's take them in order:
The ST_GeomFromText
geometry constructor accepts coordinates in X,Y order, but you've specified them in Latitude,Longitude order, which is Y,X (37.8E 26.7N is in Saudi Arabia)
The ST_GeomFromText
constructor requires SRID of the provided coordinates, which, for WGS1984 decimal degrees, is 4326
You've specified your decimal degrees coordinates to fifteen decimal places. Using a rough conversion factor of 111,120 meters per degree (based on 60 nautical miles), you're asserting precision to 1.11e-10 meters (which is 1.11 angstroms, less than the distance of the carbon-carbon covalent bond). Even if you lop off nine of those digits, you'll still be within a hand-span of the specified location.
When specifying a projection with ST_Transform
you must be careful to use an appropriate SRID for the geographic area being evaluated. You've chosen a conic projection over the United States instead of Greece, which will, at best, produce random results. Instead, use the appropriate SRID, specified elsewhere in the query (ST_Transform(...,2100)
)
The ST_Distance
function returns values in the projection in which the operation was performed, which for SRID 2100 is meters. Converting to kilometers only requires division by 1000 (ST_Distance(...) / 1000 as Km
)
The ST_DWithin
function also operates in the projection units, so instead of limiting to 50km, you've limited to 50 meters (ST_DWithin(...,...,50000)
)
So, putting it all together, you get:
SELECT gid,
name,
ST_Distance(
g1.geom,
ST_Transform(
ST_GeomFromText(
'POINT(26.6980043 37.791459)',
4326),
2100)) / 1000.0 as km
FROM samos g1
WHERE ST_DWithin(
g1.geom,
ST_Transform(
ST_GeomFromText(
'POINT(26.6980043 37.791459)',
4326),
2100),
50000)
ORDER BY ST_Distance(
g1.geom,
ST_Transform(
ST_GeomFromText(
'POINT(26.6980043 37.791459)',
4326),
2100))
LIMIT 5;
(I didn't build a sample dataset to test this, so it needs validation).
[NOTE: Edited to remove unneeded ST_Transform from g1.geom (2100) to 2100]
Once you get this working, there are plenty of SQL optimizations left, but that can be a different question (in a different SE group).