@@ -1847,6 +1847,77 @@ def test_segmentize(self):
18471847 def test_transform (self ):
18481848 pass
18491849
1850+ def test_rotate (self ):
1851+ geoms = [
1852+ Point (1 , 1 ),
1853+ LineString ([(1 , - 1 ), (1 , 0 )]),
1854+ Polygon ([(3 , - 1 ), (4 , 0 ), (3 , 1 )]),
1855+ None ,
1856+ ]
1857+ s = GeoSeries (geoms )
1858+
1859+ # Test default
1860+ result = s .rotate (90 )
1861+ expected = gpd .GeoSeries (
1862+ [
1863+ Point (1.0 , 1.0 ),
1864+ LineString ([(1.5 , - 0.5 ), (0.5 , - 0.5 )]),
1865+ Polygon ([(4.5 , - 0.5 ), (3.5 , 0.5 ), (2.5 , - 0.5 ), (4.5 , - 0.5 )]),
1866+ None ,
1867+ ]
1868+ )
1869+ self .check_sgpd_equals_gpd (result , expected )
1870+
1871+ # Test with explicit origin tuple (90 degrees around 0,0)
1872+ result = s .rotate (90 , origin = (0 , 0 ))
1873+ expected = gpd .GeoSeries (
1874+ [
1875+ Point (- 1.0 , 1.0 ),
1876+ LineString ([(1.0 , 1.0 ), (0.0 , 1.0 )]),
1877+ Polygon ([(1.0 , 3.0 ), (0.0 , 4.0 ), (- 1.0 , 3.0 ), (1.0 , 3.0 )]),
1878+ None ,
1879+ ]
1880+ )
1881+ self .check_sgpd_equals_gpd (result , expected )
1882+
1883+ # Test use_radians
1884+ import math
1885+
1886+ result = s .rotate (math .pi / 2 , origin = (0 , 0 ), use_radians = True )
1887+ self .check_sgpd_equals_gpd (result , expected )
1888+
1889+ # Test with a Point object as the origin
1890+ result = s .rotate (90 , origin = Point (0 , 0 ))
1891+ self .check_sgpd_equals_gpd (result , expected )
1892+
1893+ # Test origin='centroid'
1894+ result = s .rotate (45 , origin = "centroid" )
1895+ expected = gpd .GeoSeries (
1896+ [
1897+ Point (1.0 , 1.0 ),
1898+ LineString (
1899+ [
1900+ (1.3535533905932737 , - 0.8535533905932737 ),
1901+ (0.6464466094067263 , - 0.14644660940672627 ),
1902+ ]
1903+ ),
1904+ Polygon (
1905+ [
1906+ (3.8047378541243653 , - 0.9428090415820636 ),
1907+ (3.8047378541243653 , 0.4714045207910314 ),
1908+ (2.3905242917512703 , 0.4714045207910314 ),
1909+ (3.8047378541243653 , - 0.9428090415820636 ),
1910+ ]
1911+ ),
1912+ None ,
1913+ ]
1914+ )
1915+ self .check_sgpd_equals_gpd (result , expected )
1916+
1917+ # Test invalid origin strings
1918+ with pytest .raises ((ValueError , TypeError )):
1919+ s .rotate (90 , origin = "invalid" )
1920+
18501921 def test_force_2d (self ):
18511922 s = sgpd .GeoSeries (
18521923 [
0 commit comments