53
Lúa gạo Việt Nam và những con số (Dân Việt) - Gạo là lương thực quan trọng nhất ở Việt Nam. Nó cũng là nguồn lương thực quan trọng nhất cho hơn nửa loài người, nhất là ở các nước Đông Á, Đông Nam Á và Nam Á. Với người Việt dù bất cứ ở đâu, “ăn cơm” chỉ việc ăn nói chung gồm nhiều thứ chứ không chỉ có cơm. Cơm, gạo, thóc, lúa là những từ thuần Việt và đã gắn với lịch sử, với cuộc sống của người Việt từ ngàn đời nay. Từ ĐBSCL, qua miền Trung, đến đồng bằng Bắc Bộ và lên tận rẻo cao, người Việt dù thuộc sắc tộc nào cũng đều biết trồng lúa. Và lúa, gạo sẽ còn gắn với người Việt lâu dài, dù với sự phát triển, có thể người Việt sẽ tiêu thụ ngày càng ít gạo đi, dù số lao động trực tiếp làm ra lúa gạo có giảm đi.

Gis Sample

Embed Size (px)

Citation preview

Page 1: Gis Sample

Lúa gạo Việt Nam và những con số(Dân Việt) - Gạo là lương thực quan trọng nhất ở Việt Nam. Nó cũng là nguồn lương thực quan trọng nhất cho hơn nửa loài người, nhất là ở các nước Đông Á, Đông Nam Á và Nam Á.Với người Việt dù bất cứ ở đâu, “ăn cơm” chỉ việc ăn nói chung gồm nhiều thứ chứ không chỉ có cơm. Cơm, gạo, thóc, lúa là những từ thuần Việt và đã gắn với lịch sử, với cuộc sống của người Việt từ ngàn đời nay.Từ ĐBSCL, qua miền Trung, đến đồng bằng Bắc Bộ và lên tận rẻo cao, người Việt dù thuộc sắc tộc nào cũng đều biết trồng lúa. Và lúa, gạo sẽ còn gắn với người Việt lâu dài, dù với sự phát triển, có thể người Việt sẽ tiêu thụ ngày càng ít gạo đi, dù số lao động trực tiếp làm ra lúa gạo có giảm đi.

 

Theo số liệu của Tổ chức Lương thực và Nông nghiệp (FAO) của Liên Hợp Quốc, Việt Nam đứng đầu thế giới về hạt tiêu và hạt điều, gạo đứng thứ 5 cùng với cao su và đậu đỗ. Việt Nam có 24 mặt hàng nông nghiệp thực phẩm đứng hàng từ 1 đến 10 thế giới (37 mặt hàng đứng từ hàng 1 đến 20) cho thấy vai trò của cácsản phẩm nông nghiệp Việt Nam.

Page 2: Gis Sample

Xét về sản lượng gạo, năm 2009 Việt Nam đứng thứ 5 sau Trung Quốc (197 triệu tấn), Ấn Độ (131 triệu tấn), Indonesia (64 triệu tấn) và Banglades (45 triệu tấn).Xét về thứ hạng trong nước, theo sản lượng, gạo là sản phẩm nông nhiệp hàng đầu của Việt Nam với tổng sản lượng (năm 2009) là 38,9 triệu tấn, tính ra tiền là 10,4 tỷ USD. Năm 2011 Bộ NNPTNT dự tính sản lượng gạo Việt Nam là 42 triệu tấn. Năm 2009 Việt Nam xuất khẩu 5,969 triệu tấn gạo (chiếm 15,35% sản lượng) và năm 2011 chắc đạt 7 triệu tấn gạo xuất khẩu.Thái Lan tuy đứng thứ 7 thế giới về sản lượng (năm 2009: 31,5 triệu tấn, sau Myanmar 32,7 triệu tấn) nhưng đứng đầu thế giới về xuất khẩu gạo (Việt Nam xếp thứ 2).Theo Tổng cục Thống kê, xuất khẩu gạo của Việt Nam năm 1995 là 1,988 triệu tấn và đến năm 2010 là 6,886 triệu tấn (năm 2011 chắc chắn vượt 7 triệu tấn!). Có thể thấy lượng xuất khẩu gạo của Việt Nam trong 16 năm qua đã tăng gần 3,5 lần và đóng góp không nhỏ cho xuất khẩu của Việt Nam (năm 2010 đạt 3,23 tỷ USD chiếm 4,5% tổng kim ngạch xuất khẩu của cả nước).Nhắc tới những con số trên, nếu nhìn lại 25-30 năm trước, những năm cuối 1970 và các năm 1980, khi cả nước thiếu gạo ăn và mãi đến 1988 Việt Nam vẫn cần nhập khẩu 0,45 triệu tấn gạo, rồi người nông dân thực sự giành lại được quyền tự do sản xuất của mình và 2 năm sau, năm 1990 Việt Nam đã có thể xuất khẩu 1 triệu tấn gạo, chúng ta có thể thấy sức sống của người nông dân Việt Nam mạnh mẽ đến thế nào nếu không bị chính sách sai lầm cản trở. Nếu chính sách của Nhà nước thúc đẩy, hỗ trợ hoạt động của bà con nông dân thì thành tích lúa gạo của Việt Nam còn cao hơn nữa.Các nước công nghiệp có tỷ lệ lao động nông nghiệp trên tổng lao động rất nhỏ. Tỷ lệ giảm nhanh nhưng sản lượng tuyệt đối vẫn tăng đáng kể.Năm 2010, tỷ lệ lao động nông nghiệp là 17% ở Ba Lan, 12,7% ở Malaysia, 5,2% ở Hàn Quốc, 2,22% ở Nhật Bản và 2% ở Pháp. Tỷ lệ này ở ta là 63,2%! Muốn trở thành nước công nghiệp hiện đại chí ít sau 30 năm nữa chúng ta cần có cơ cấu lao động nông nghiệp cỡ 10% khoảng như ở Malaysia hiện nay!Quốc hội bàn cố làm sao giữ cho được 3,8 triệu ha diện tích trồng lúa. Nếu giữ được 3,8 triệu ha trong tương lai 25-30 năm có lẽ chỉ cần 10-20 nghìn trang trại trồng lúa quy mô lớn (từ vài trăm đến 1.000 ha/trang trại) với số lao động từ vài chục đến vài trăm người một trang trại. Nói cách khác số lao động sản xuất lúa hàng hóa sẽ chỉ còn cỡ 2-3 triệu người.Không có số liệu lao động làm lúa gạo, nhưng có thể dự cảm từ con số lao động năm 2010 trong nông nghiệp là 29,63 triệu trong tổng số 46,91 triệu lao động (theo FAO), thì có thể thấy thách thức là vô cùng to lớn.Số lao động nông nghiệp là 29,63 triệu và mức tăng là 1,22%/năm. Đấy là các số liệu xuất phát. Hãy xét vài kịch bản phát triển.Giả sử, mức tăng lao động không đổi và mỗi năm chuyển được 1 triệu lao động nông nghiệp sang lĩnh vực công nghiệp và dịch vụ, thì sau 30 năm số lao động trong nông nghiệp sẽ còn 6,87 triệu (khi đó tổng lao động sẽ là 68,3 triệu), nói cách khác lao động nông nghiệp sẽ chiếm 10,47%. Nếu mỗi năm chỉ chuyển được 0,5 triệu lao động khỏi nông nghiệp, thì sau 30 năm vẫn còn 24,08 triệu lao động nông nghiệp (chiếm 36,75% tổng lao động).Nếu mức tăng lao động giảm được xuống 1%/năm, và số lao động rút ra khỏi lĩnh vực nông nghiệp vẫn là 1 triệu/năm (0,5 triệu/năm), thì sau 30 năm số lao động nông nghiệp còn 6,09 triệu chiếm 9,73% lao động (22,82 triệu chiếm 36,45% lao động).Có thể thấy giảm tốc độ tăng lao động cũng có tác động đáng kể, nhưng việc chuyển lao động nông nghiệp sang công nghiệp và dịch vụ vẫn phải là nhiệm vụ chính. Với việc rút 1 triệu lao động khỏi lĩnh vực nông nghiệp, thì Việt Nam cần 30 năm mới đạt tỷ lệ lao động nông nghiệp

Page 3: Gis Sample

xuống cỡ 10% (mức tương tự như của Malaysia hiện nay), còn rút 0,5 triệu/năm thì sau 30 năm nữa vẫn chưa thể gọi là có cơ cấu lao động của một nền kinh tế hiện đại.Cần hết sức nỗ lực mới có thể làm được và phải làm nếu muốn đất nước có nền nông nghiệp tiên tiến! Có chính sách ra sao để giúp bà con nông dân tiến hành sự chuyển đổi vĩ đại này là trách nhiệm hết sức lớn đối với Nhà nước và toàn xã hội.

TS Nguyễn Quang A

Chính sách lúa gạo ở Việt Nam: Cần “hệ điều hành” mớiThư Sau, 11.11.2011 | 07:04 (GMT + 7)

Trong điều kiện hiện nay và chắc chắn sẽ còn rất lâu, an ninh lương thực vẫn là vấn đề mang tính toàn cầu và VN vẫn là quốc gia đóng góp có trách nhiệm cho thế giới.Chúng ta xac định lúa gạo là vấn đề chiến lược và đã có nhiều chính sach tốt, song khi mà nhiều quốc gia sản xuất lúa gạo hàng đầu đã đưa ra những điều chỉnh quan trọng về chính sach, VN cũng phải nghĩ đến một “hệ điều hành” mới, sao cho vẫn giữ vững nguyên tắc “2 bảo đảm” - an ninh lương thực quốc gia và nâng cao thu nhập cho người trồng lúa - đồng thời bổ sung tính linh hoạt.   Theo TS Trần Văn Đạt - nguyên chanh chuyên gia của FAO (“Thai Lan thay đổi chính sach lúa gạo, còn Việt Nam?”, tài liệu Festival Lúa gạo VN lần II), để ưu tiên mục tiêu tăng lợi nhuận cho người trồng lúa, cường quốc số 1 xuất khẩu gạo Thai Lan đã có những điều chỉnh về chính sach, chấp nhận sẽ giảm bớt khoảng 2 triệu tấn gạo mỗi năm và “nhường” ngôi vị quan quân cho VN mà họ nắm giữ nhiều năm liền.

Mô hình VFA vừa độc quyền xuất khẩu gạo, vừa ấn định giá lúa sẽ chấm dứt năm 2012 (biểu tượng VFA trên “Con đường lúa gạo” tại Festival Lúa gạo VN lần II). Ảnh: Dương Thu

Tương tự là Trung Quốc, mặc dù với diện tích đất trồng lúa mênh mông, nhiều gấp 10 lần nước ta, nhưng họ chủ trương chỉ sản xuất gạo vừa đủ để đảm bảo an ninh lương thực quốc gia, nên đã giảm từ 37 triệu hécta năm 1976 xuống còn 30 triệu hécta năm 2009. Tại hội thảo “Định vị thương hiệu gạo Việt” trong khuôn khổ Festival Lúa gạo VN lần II, ý kiến của nhiều chuyên gia, nhà nghiên cưu và thương gia cũng đề cập đến yêu cầu thay đổi chiến lược xuất khẩu gạo, xây dựng thương hiệu, tập trung vào phân khúc chất lượng cao để nâng cao và hoàn thiện chuỗi gia trị giúp tăng lợi nhuận cho người trồng lúa. Trước yêu cầu đó, đề nghị những nhà hoạch định chính sach lúa gạo VN quan tâm mấy việc:Một là, tiếp cận linh hoạt hơn đối với quy hoạch sử dụng đất trong việc thực hiện chủ trương giữ 3,81 triệu hécta đất trồng lúa đã được Đảng và Nhà nước khẳng định. Trong đó, phân biệt khu vực trồng lúa “trọng yếu” và “không trọng yếu” dựa trên sự phù hợp về sinh thai nông nghiệp, năng suất, tac động của biến đổi khí hậu. 

Page 4: Gis Sample

Hai là, ap dụng phân vùng theo không gian, có chính sach hỗ trợ khac nhau ở “vùng lõi”, “vành đai” và cac khu vực trồng lúa bình thường khac, có xem xét mục tiêu sản xuất lúa cho an ninh lương thực hay lúa hàng hóa. Tach biệt hẳn cac hệ thống và chiến lược xuất khẩu gạo mang “tính xã hội” và tính thương mại để có chính sach rõ ràng, phân biệt giữa 2 mục tiêu, để tăng cường hỗ trợ nhóm thực hiện mục tiêu chính trị - xã hội, giải phóng một phần ganh nặng để tăng lợi nhuận, đồng thời cũng nâng cao trach nhiệm cho nhóm thương mại. Định hướng lại trọng tâm, chuyển từ cac chưc năng thương mại sang tập trung vào cac mục tiêu xã hội, “hàng hóa công” và quản trị rủi ro.Ba là, tiếp tục tăng cường chiến lược đa ngành, lồng ghép nhiều chương trình mục tiêu như xây dựng nông thôn mới, xóa đói giảm nghèo, chống suy dinh dưỡng trẻ em... để cùng đảm đương nhiệm vụ an ninh lương thực và chống suy dinh dưỡng chư không đặt hết ganh nặng lên vai người trồng lúa.    

Festival Lúa gạo VN lần II: Thương hiệu yếu, khó nâng giá trị xuất khẩuSáng 10.11, dưới sự chủ trì của Thứ trưởng Bộ NNPTNT Diệp Kỉnh Tần, Hội thảo quốc tế “Con đường phát triển lúa gạo chất lượng cao VN” được tổ chức với sự tham dự của các chuyên gia hàng đầu về lúa gạo VN ở trong và ngoài nước.Tại cuộc hội thảo, một lần nữa các đại biểu nhấn mạnh, để hạt gạo VN đem về cho đất nước nhiều ngoại tệ hơn, cần thay đổi tư duy từ người trồng lúa cho đến nhà xuất khẩu. Không thể sản xuất nhỏ lẻ theo kiểu nông hộ mà phải sản xuất tập trung theo mô hình cánh đồng mẫu lớn hay thành lập Cty cổ phần nông nghiệp để đưa các giống lúa cho phẩm chất gạo tốt, có thương hiệu vào sản xuất với quy mô lớn đáp ứng cho nhu cầu xuất khẩu.Tham luận của Cục Trồng trọt – Bộ NNPTNT cho rằng, hiện nay ĐBSCL có nhiều bộ giống mới dựa trên thành tựu của công nghệ sinh học, nhưng hầu hết đều không giữ được chất lượng lâu dài, do kỹ thuật canh tác lạc hậu, hạt gạo còn lẫn nhiều tạp chất. Chính vì vậy mà chất lượng gạo không cao, khó tiêu thụ tại thị trường khó tính. Nhiều đại biểu tin rằng, VN hoàn toàn có khả năng sản xuất gạo có thương hiệu mạnh như Thái Lan, tuy nhiên do còn vướng nhiều cơ chế, chính sách nên khó làm. Điển hình như Sóc Trăng, sau 20 năm mới sản xuất thành công các giống lúa thơm ST (từ ST1 đến ST 20) nhưng muốn sản xuất đại trà thì rất khó do đất đai thuộc quyền sử dụng của nông hộ.     N.H

* Theo dự báo của FAO, tổng sản lượng gạo thế giới năm 2011 vào khoảng 463,8 tấn, sản lượng gạo thương mại khoảng 31,4 triệu tấn. Với tổng sản lượng gạo xuất khẩu 7 triệu tấn năm nay, VN chiếm khoảng 22,3% và ĐBSCL sẽ chiếm khoảng 20% sản lượng gạo thương mại của thế giới.* “Trên thế giới ngày nay, lúa gạo được coi là một mặt hàng chính trị hơn là mặt hàng kinh tế, tỉ trọng lúa gạo buôn bán trên thị trường còn thấp hơn nhiều so với tổng sản lượng sản xuất ra hằng năm; giá cả trên thị trường quốc tế lệ thuộc nhiều vào chính sách an ninh lương thực... Do vậy, nếu đặt mục tiêu sản xuất lúa với mục đích an ninh lương thực quốc gia, Nhà nước cần có chính sách thích hợp cho người trồng lúa, làm cho nghề trồng lúa trở nên hấp dẫn hơn”. (TS Lê Văn Bảnh - Viện trưởng Viện Lúa ĐBSCL)

Trần Hữu Hiệp

Page 5: Gis Sample

Lúa gạo Việt Nam: Năng suất cao, tổn thất lớn

> Định vị thương hiệu lúa gạo phải từ nông dân

TP - Lúa gạo Việt Nam có giống tốt, năng suất thuộc loại cao nhất thế giới, nhưng tổn thất

sau thu hoạch lớn gấp 2-3 lần so với Ấn Độ, Nhật Bản…

Đó là nhận định chung tại các cuộc hội thảo khoa học trong khuôn khổ Festival Lúa gạo Việt Nam lần

hai ở tỉnh Sóc Trăng (từ ngày 8 đến 11-11).

Thu hoạch lúa ở ĐBSCL .

9-11 tấn/ha

Lúa ở nhiều địa phương ĐBSCL đạt năng suất bình quân 7 tấn/ha/vụ, được cho là cao nhất thế giới. Đặc

biệt, giống OM6976 được đưa vào khảo nghiệm ở nhiều tỉnh ĐBSCL đạt năng suất 9-11 tấn/ha/vụ mà

Trung tâm Khảo kiểm nghiệm Giống-Sản phẩm cây trồng vùng Nam Bộ đánh giá “có thể coi là sự đột

phá về năng suất”.

Trong 3 năm từ 2008 đến 2011, ở ĐBSCL, có hàng trăm giống lúa lai tạo từ các cơ sở nghiên cứu đưa

ra khảo nghiệm và đã được phép sản xuất đại trà 31 giống, sản xuất thử 48 giống. Ước tính, diện tích

sản xuất giống mới mỗi năm đạt 600.000 – 800.000 ha.

Trong đó, khoảng 90% giống lúa đến từ Viện Lúa ĐBSCL và nơi đây đã chọn được những giống lúa

ngắn ngày giàu chất sắt, kháng sâu bệnh và năng suất cao, thích nghi vùng nhiễm phèn mặn. Viện

Nghiên cứu Duyên hải Nam Trung Bộ có giống chịu hạn, trồng ở Tây Nguyên đạt năng suất 7

tấn/ha/vụ; trồng ở Nam Trung Bộ đạt 6,5 tấn/ha/vụ.

Thành công trong công tác giống còn phải kể đến việc phổ biến rộng rãi cho nông dân với chủ trương

khuyến khích cộng đồng làm giống. Hạt giống đầu dòng từ các cơ sở nghiên cứu chỉ đáp ứng 3 – 5%

diện tích gieo trồng, nhưng ở tỉnh An Giang, 90% diện tích gieo sạ sử dụng giống tương đương xác

nhận, nhờ hàng trăm tổ và hộ nông dân sản xuất giống.

Mất hơn 10.000 tỷ đồng/năm

TS Phạm Văn Tấn ở Phân viện Cơ điện nông nghiệp và Công nghệ sau thu hoạch cho biết, ĐBSCL có

mức tổn thất sau thu hoạch lên tới 13,7%, trong khi Ấn Độ có tỷ lệ 6%, Nhật Bản 3,9-5,6%. Tổn thất lớn

ở 2 công đoạn: sấy 4,2% và tồn trữ 2,6%.

Tổng sản lượng lúa của ĐBSCL năm 2011 là 23 triệu tấn; tổn thất ở hai khâu này là gần 1,6 triệu tấn.

Với giá 7.000 đồng/kg, số tiền mất là hơn 10.000 tỷ đồng.

Page 6: Gis Sample

Tổn thất từ sấy còn dẫn tới tổn thất trong xay xát ở mức cao 3%. Lúa không được sấy đúng kỹ thuật,

không đạt độ ẩm cần thiết 13-14% nên khi xay xát, hạt gạo nguyên và trắng thu được rất thấp. Một

nghiên cứu của Đại học Nông lâm TPHCM cho thấy, lúa có độ ẩm 14% khi xay xát sẽ được 50% gạo

nguyên, nhưng nếu độ ẩm 16% thì gạo nguyên chỉ còn 34%. Hiện nay, lúa sấy đúng kỹ thuật của

ĐBSCL chỉ khoảng 38% tổng sản lượng.

TS Tấn cho biết, quy trình công nghệ sau thu hoạch ở ĐBSCL hiện nay là quy trình ngược. Lúa thu

hoạch xong được nông dân và thương lái phơi sấy sơ qua, đem bán cho doanh nghiệp xay xát, lau

bóng, khi đã thành gạo rồi mới tiếp tục sấy đến độ ẩm 14% để đóng bao tiêu thụ. Tình trạng này kéo

dài có nguyên nhân ở công nghệ sấy lúa lạc hậu.

ĐBSCL sử dụng lò sấy tĩnh vỉ ngang và sấy đứng, không thể sấy được lúa có độ ẩm trên 30%, mà hầu

hết lúa hè thu ở ĐBSCL có độ ẩm rất cao lại cần sấy trong thời gian ngắn vì gieo sạ đồng loạt để tránh

rầy và thu hoạch trong mùa mưa. TS Tấn đề nghị “cần công nghệ sấy lúa mới”.

Theo nhiều chuyên gia, cần tổ chức lại chuỗi cung ứng sau thu hoạch thật gọn và hiệu quả. Trong đó,

huấn luyện cũng như đầu tư cho nông dân và thương lái để họ có khả năng sấy lúa đến độ ẩm 18-25%

là rất quan trọng, sau đó doanh nghiệp sấy tiếp đạt độ ẩm 14% trước khi đưa vào xay xát. 

Lũ lụt luôn là mối hiểm hoạ đặc biệt đối với các đô thị lớn, điển hình là Kuala Lumpur. Biến đổi sử dụng đất là một trong những nhân tố ảnh hưởng đến lũ lụt. Bài viết này đề cập đến việc sử dụng GIS và Viễn Thám trong nghiên cứu dự báo lũ lụt tại Klang Valley (Kuala Lumpur).

Trong nghiên cứu này Mô hình số độ cao (DEM) được nội suy từ bản đồ địa hình có đường đẳng cao là 20 mét. Toàn bộ lưu vực sông được chia thành các lưu vực phụ sau đó mô hình hoá thuỷ văn. Mức độ ngập lụt được dự báo bằng mô hình SCS TR-55 (Soil Conservation Service Technical Release 55). Công việc tính dòng chảy tràn dựa trên phương pháp Runoff Curve Number, một phuơng pháp dựa trên hiện trạng sử dụng đất của khu vực nghiên cứu. Bản đồ hiện trạng sử dụng đất được thành lập từ ảnh vệ tinh SPOT-XS và dữ liệu về lượng mưa được sử dụng làm dữ liệu để tính toán.

1. Giới thiệu

Lưu vực sông Klang thuộc khu vực bờ biển phía Tây của bán đảo Peninsular Malaysia. Hầu hết diện tích của lưu vực đã bị đô thị hoá và vẫn đang tiếp tục đô thị hoá với tốc độ cao trong đó bao gồm cả thủ đô Kuala Lumpur. Việc đô thị hoá nhanh có thể là nguyên nhân gia tăng quá trình lắng cặn và ô nhiễm. Đã có nhiều dự án di dân được thực hiện, khi mà vấn đề lũ lụt vấn đang là một loại thiên tai tự nhiên đe doạ tới khu vực này.

Page 7: Gis Sample

Lũ lụt là một trong những mối hiểm hoạ tự nhiên phổ biến và là nguyên nhân mất hàng tỷ đô la mỗi năm. Việc chuyển đổi sử dụng đất từ đất nông nghiệp sang đất đô thị có thể nguyên nhân chính. Theo JICA (1989), có hai yếu tố tự nhiên gây lũ lụt tại vùng này là bão gió mùa và bão có kèm mưa to. Nghiên cứu rõ nét nhất là hiện tượng khi có bão kèm mưa rất to thường hay xảy ra lũ quét. Chính vì đặc tính của lũ quét, xảy ra trong khu vực nhỏ và thời gian ngắn (3-5 giờ), nên việc nghiên cứu dự báo là rất quan trọng và việc xác định loại hình của lũ dẽ dàng hơn xác định phạm vi chịu ảnh hưởng của lũ.

Viễn thám và GIS được sử dụng rộng rãi, đặc biệt nhất là trong đánh giá các vấn đề liên quan đến thiên tai vì đây là nhu cầu để xác định phạm vi và thông tin chi tiết về khu vực, diện tích bị ảnh hưởng từ thiên tai cũng như các hoạt động cứu trợ, khôi phục. Thông tin viễn thám rất phù hợp các biện pháp thông thường trong việc tiếp cận, điều tra khu vực đang bị lũ lụt.

Bài viết này sẽ thảo luận về việc sử dụng DEM và ảnh vệ tinh SPOT làm thông số cơ sở cho mô hình thuỷ văn SCS TR-55) làm dự báo lũ thông qua 4 điểm đo trên sông.

2.Mô hình số độ cao

Mô hình số độ cao DEM được tạo lập từ bản đồ địa hình 1:50 000, khoảng cao đều 20 mét theo 2 bước. Bước 1 là chuyển đổi bản đồ địa hình từ dạng đường sang dạng điểm độ cao. Bước thứ 2 là nội suy địa hình theo phương pháp TIN (triangulated irregular network).

Thông tin được chiết xuất bằng 2 cách, bằng phân tích định tính hoặc định lượng trên dữ liệu số độ cao. Tù mô hình số độ cao có thể tạo các hướng nhìn khác nhau, phân tích độ dốc, địa hình, thuỷ văn và mô phỏng lũ.

3.Lưu vực

Với mục đích mô hình hoá thuỷ học thì việc chia lưu vực là cần thiết. Theo Mc Cuen, (1998), ranh giới của một lưu vực được định nghĩa là tập hợp của tất cả các điểm thu nước chạy về 1 cửa sông và nước sẽ chạy theo hướng có độ dốc lớn nhất. Trong phương pháp này DEM được sử dụng thay thế các đường đẳng cao.

Page 8: Gis Sample

Những điều kiện cần của phương pháp Graphical Peak Discharge là khu vực nghiên cứu được chia thành những lưu vực nhỏ đồng nhất

4. Phân tích dữ liệu Viễn thám

Ảnh vệ tinh SPOT-XS được nắn chỉnh bằng thuật toán đa thức với 20 điểm khống chế. Sử dụng phương pháp phân loại có kiểm định ảnh để phân loại hiện trạng sử dụng đất trong khu vực có 4 trạm đo. Khu vực thử nghiệm được giới hạn bằng bản đồ địa hình (1991) khu vực Kuala Lumpur. Khu vực đồng nhất được xác định tại 4 điểm đo là tất cả khu vực đô thị.

5. Mô hình hoá thuỷ văn

Mô hình SCS TR55 (USDA, 1986) làm đơn giản hoá việc đánh giá khả năng tiêu thoát và dòng chảy tràn trong một lưu vực nhỏ. Chúng được nhấn mạnh đối với khu vực đô thị và những lưu vực đang đô thị hoá.

Có hai phương pháp được sử dụng trong mô hình này là: - 1. Phương pháp số đường cong tiêu thoát - 2. Phương pháp dòng chảy tràn (xem chi tiết công thức tại http://www.gisdevelopment.net/aars/acrs ... 4106.shtml)

Page 9: Gis Sample

6.Thảo luận

Qua phân tích sơ bộ bằng mô hình TR55 cho thấy đây là mô hình dự báo ngập lụt có thể áp dụng được trong lưu vực thành thị như Kuala Lumpur, Malaysia. Việc sử dụng DEM để phân loại các khu vực đồng nhất rất dễ dàng bởi hầu hết các phần mềm GIS. Sự thay đổi sử dụng đất có thể dễ dàng ghi nhận bởi ảnh vệ tinh.

Mô hình thuỷ văn được sử dụng trong bài viết này dựa trên hệ thống phân loại đất của Mỹ và khả năng thích hợp khi ứng dụng vào Malaysia vẫn còn chưa chắc chắn. Cần đầu tư cho nghiên cứu để làm cơ sở lý luận và thực tiến trong các tình huống thực tế.

Có thể thấy việc tích hợp Viễn thám và GIS có triển vọng rất cao trong việc dự đoán ngập lụt. Trong quản lý thiên tai chúng có thể chỉ ra các khu vực bị ảnh hưởng và sẽ dễ dàng hành động để giảm thiệt hại cho cộng đồng.

_________________HungGIS Pro

Ứng dụng SWAT cho Hồ chứa Đại Lải

Thư viện xin gửi đến quý bạn đọc bài bao "Nghiên cứu ứng dụng mô hình toán thông số phân bố SWAT để đánh giá ảnh hưởng của việc sử dụng đất đến bồi lắng hồ chứa nước, ứng dụng tính toán cho lưu vực hồ chứa  nước Đại Lải." do TS. Phạm Thị Hương Lan - Bộ Môn Chỉnh trị sông và Bờ biển thuộc Trường Đại học Thủy Lợi biên soạn

Tóm tắtMột trong những nguyên nhân gây nên bồi lắng hồ chứa là do tác

động của con người đến thảm phủ trên bề mặt lưu vực. Vì vậy, việc đánh giá ảnh hưởng của việc sử dụng đất đến bồi lắng hồ chứa là cần thiết để từ đó đề xuất được các biện pháp giảm thiểu bồi lắng lòng hồ. Báo cáo này giới thiệu một công cụ mạnh hiện nay, đó là nghiên cứu ứng dụng mô hình toán thông số phân bố SWAT để đánh giá ảnh hưởng của việc sử dụng đất đến bồi lắng hồ chứa nước, ứng dụng tính toán cho lưu vực hồ chứa  nước Đại Lải.1. Mở đầu

Lâu nay chúng ta chỉ quan tâm đến việc tính toan bồi lắng hồ chưa mà chưa có nhiều nghiên cưu cụ thể về việc đanh gia ảnh hưởng của cac yếu tố khac như việc sử dụng đất đến bồi lắng, do đó cac biện phap giảm

Page 10: Gis Sample

thiểu bồi lắng mới chỉ đưa ra ở mưc độ chung chung, chưa cụ thể. Cac nghiên cưu trước đây cũng chỉ nghiên cưu đanh gia hiện trạng xói mòn bề mặt lưu vực, chưa tính toan tổng lượng bùn cat vận chuyển đến hồ chưa. Do đó, việc nghiên cưu đanh gia ảnh hưởng của việc sử dụng đất đến bồi lắng hồ chưa là cần thiết.

Hồ chưa nước Đại Lải nằm ven chân núi Tam Đảo thuộc địa phận huyện Mê Linh tỉnh Vĩnh Phúc (trước kia là tỉnh Vĩnh Phú) được xây dựng trong những năm 1960 - 1970 với nhiệm vụ chính là cấp nước tưới cho 2700 -  3000 ha đất canh tac của huyện Tam Đảo, Mê Linh (Vĩnh Phúc) và Sóc Sơn (Hà Nội). Lưu vực hồ Đại Lải nằm trong vùng nhiệt đới gió mùa có cac hình thế diễn biến thời tiết diễn biến phưc tạp, mưa với cường độ lớn nên dẫn đến hiện tượng xói mòn bề mặt lưu vực tương đối lớn. Mặt khac cac hoạt động khai thac lưu vực vì mục đích kinh tế càng làm gia tăng hiện tượng xói mòn bề mặt lưu vực. Lượng bùn cat bị xói mòn làm gia tăng lượng dòng chảy bùn cat đến hồ, do đó làm tăng lượng bùn cat bồi lắng trong hồ. Với lý do đó, bài bao đi sâu giới thiệu việc ưng dụng mô hình toan thông số phân bố SWAT dự tính lượng dòng chảy bùn cat đến hồ chưa, từ đó phân tích cac nguyên nhân ảnh hưởng đến việc gia tăng lượng dòng chảy bùn cat đến hồ, đề ra cac biện phap làm giảm thiểu lượng bùn cat đến hồ.2. Ứng dụng mô hình toán thông số phân bố SWAT tính toán lượng dòng chảy bùn cát đến hồ chứa nước Đại Lải            Giới thiệu chung về mô hình SWAT

Mô hình “Công cụ đanh gia đất và nước“ SWAT (Soil and Water Assement Tools) là một mô hình vật lý được xây dựng từ những năm 90’s do tiến sỹ Dr. Jeff Arnold thuộc trung tâm nghiên cưu đất nông nghiệp USDA- Agricultural Research Service (ARS) xây dựng nên. Mô hình này được xây dựng để mô phỏng ảnh hưởng của việc quản lý sử dụng đất đến nguồn nước, bùn cat và hàm lượng chất hữu cơ trong đất trên hệ thống lưu vực sông trong một khoảng thời gian nào đó. Tiền thân của mô hình SWAT là mô hình SWRRB ((Simulator for Water Resources in Rural Basins) (Williams et al., 1985; Arnold et al., 1990)) và mô hình ROTO ((Routing Outputs to Outlet) (Arnold et al., 1995)). Mô hình chia lưu vực ra làm cac vùng hay cac lưu vực nhỏ. Phương phap sử dụng cac lưu vực nhỏ trong mô hình khi mô phỏng dòng chảy là rất tiện lợi khi mà cac lưu vực này có đủ số liệu về sử dụng đất cũng như đặc tính của đất...

Xét về toàn lưu vực thì mô hình SWAT là một mô hình phân bố. Mô hình này chia dòng chảy thành 3 pha: pha mặt đất, pha dưới mặt đất (sat mặt, ngầm) và pha trong sông. Việc mô tả cac qua trình thuỷ văn được chia làm hai phần chính: Phần thư nhất là pha lưu vực với chu trình thuỷ văn kiểm soat khối lượng nước, bùn cat, chất hữu cơ  và được chuyển tải tới cac kênh chính của mỗi lưu vực. Phần thư hai là diễn toan dòng chảy, bùn cat, hàm lượng cac chất hữu cơ tới hệ thống kênh và tới mặt cắt cửa ra của lưu vực.- Pha mặt đất diễn tả cac thành phần dòng chảy mặt, phần xói mòn.- Pha sat mặt diễn tả cac thành phần dòng chảy sat mặt, dòng chảy ngầm.- Pha trong sông diễn tả diễn toan lượng dòng chảy tới mặt cắt cửa ra của lưu vực.

Ứng dụng mô hình toán thông số phân bố SWAT tính toán

Page 11: Gis Sample

lượng dòng chảy bùn cát đến hồ chứa nước Đại LảiSố liệu đầu vào của mô hình SWAT bao gồm số liệu không gian (cac

bản đồ) và cac số liệu thuộc tính.+ Cac số liệu không gianCac bản đồ được dùng để tính toan bao gồm:- Bản đồ địa hình lưu vực hồ Đại Lải đựơc thể hiện dưới dạng mô

hình số độ cao (DEM).- Bản đồ mạng lưới sông suối lưu vực hồ Đại Lải được mô phỏng

trực tiếp từ nền bản đồ mô hình số độ cao DEM.- Bản đồ đất lưu vực hồ Đại Lải: Trên lưu vực chủ yếu là đất

Feralit.   - Bản đồ thảm phủ tực vật ưng với hiện trạng rừng và sử dụng đất

của năm 1983 và năm 1993 trong lưu vực hồ Đại Lải.Cac số liệu không gian được xử lý bằng mô hình số hoa độ cao

(DEM). Bản đồ địa hình được đưa vào mô hình dưới dạng Grid là DEM còn bản đồ sử dụng đất và loại đất được đưa vào mô hình dưới dạng Grid hoặc Shape.

+ Cac số liệu thuộc tính bao gồm:- Vị trí địa lý cac trạm thuỷ văn trong và ngoài lưu vực hồ Đại Lải

được dùng để tính toan trong mô hình SWAT.- Số liệu khí tượng cần thiết để chạy mô hình SWAT, bao gồm nhiệt

độ không khí trung bình (tối cao, tối thấp), tốc độ gió, bưc xạ mặt trời, độ ẩm tương đối, tuyệt đối của không khí.

Số liệu khí tượng trung bình ngày của trạm Tam Đảo được dùng trong tính toan cho lưu vực hồ Đại Lải.

- Số liệu mưa trung bình ngày, lưu lượng bình quân ngày.Do mô hình chạy cho số liệu ngày, số liệu mưa ngày của cac trạm đo

trên lưu vực không đầy đủ, thời gian qua trắc không liên tục và không tương đồng với dòng chảy bình quân ngày. Vì vậy chuỗi số liệu mưa bình quân ngày tại trạm Ngọc Thanh và trạm Đại Lải sẽ được dùng trong tính toan cho mô hình SWAT.

Số liệu dòng chảy bình quân ngày tại trạm Ngọc Thanh sẽ dùng so sanh kết quả tính toan kiểm nghiệm của mô hình.

+ Kết quả tính toán thử nghiệm và kiểm định mô hình SWAT

So sánh tương quan giữa dòng chảy tính toán và thực đo tại lưu vực sông Thanh Lộc trong trường hợp thử nghiệm mô hình SWAT

Page 12: Gis Sample

 

So sánh tương quan giữa dòng chảy tính toán và thực đo tại lưu vực sông Thanh Lộc trong trường hợp thử nghiệm mô hình SWAT

Page 13: Gis Sample

 

Sau khi đã hiệu chỉnh cac thông số của mô hình thu được kết quả là giữa lưu lượng thực đo và lưu lượng tính toan trên lưu vực sông Thanh Lộc (dùng để chạy thử nghiệm mô hình) cho hệ số tương quan theo chỉ tiêu Nash là R2 = 0.79. Mô hình cho kết quả tương đối tốt. Phương trình tương quan giữa lưu lượng tính toan và lưu lượng thực đo của lưu vực sông Thanh Lộc là Y=0.80X + 0.01. Kết quả chạy kiểm nghiệm mô hình cho hệ số tương quan giữa lưu lượng tính toan và lưu lượng thực đo theo chỉ tiêu Nash là R2 = 0.85 và phương trình tương quan là Y = 0.74X + 0.03. Đây là kết quả chấp nhận được, quan hệ này kha chặt chẽ cho thấy bộ thông số đã xac định được trong phần chạy thử nghiệm mô hình là đang tin cậy.3. Đánh giá ảnh hưởng của việc sử dụng đất đến bồi lắng hồ chứa

Thống kê từ bản đồ hiện trạng rừng của lưu vực hồ Đại Lải trong hai năm 1983 và 1993 ta thấy so với năm 1983 thì diện tích rừng của năm 1993 có sự thay đổi mạnh về diện tích cũng như về loại rừng. Tỷ lệ đất trống đẵ giảm đang kể, thay vào đó là cac loại rừng tự nhiên và nhân tạo, thảm phủ thực vật được cải thiện, điều đó có tac dụng tích cực tới tài nguyên thiên nhiên cũng như giảm khả năng xói mòn bề mặt lưu vực. Tuy nhiên tỷ lệ diện tích đất nông nghiệp xen lẫn khu dân cư vẫn chiếm tỷ lệ lớn, đây là khu vực có khả năng xói mòn bề mặt cao vì thảm phủ chịu tac động tiêu cực của con người một cach liên tục do canh tac, xây dựng,…

Lưu vực hồ Đại Lải là một lưu vực có diện tích nhỏ, trên lưu vực đất

Page 14: Gis Sample

xam Feralit là chủ yếu  Đây là loại đất có độ chua lớn, tỷ lệ mùn cao vì vậy độ xói mòn của đất là tương đối lớn.

Lượng xói mòn trên bề mặt lưu vực cụ thể trên từng lưu vực con được tính toan dựa vào mô hình SWAT, kết quả tính toan như hình vẽ sau:Bản đồ hiện trạng xói mòn lưu vực hồ chứa nước Đại Lải  ứng hiện trạng rừng năm 1993

Kết quả tính toan từ mô hình cho thấy mưc độ xói mòn lưu vực ưng với hiện trạng rừng năm 1993 so với năm 1983 thì lớn hơn do sự biến đổi thảm phủ trên lưu vực, diện tích đất trống trên lưu vực của năm 1993 tăng nhiều so với năm 1983 (năm 1983 là 3.8km2 tương ưng 6.27%, còn năm 1993 là 22.88 km2 tương ưng 37.75%. Theo thống kê hiện trạng rừng năm 1993 so với hiện trạng rừng năm 1983 tuy có tăng lên về loại rừng song diện tích còn nhỏ, diện tích đất trống lớn. Kết quả tính toan cho thấy ưng với hiện trạng rừng năm 1983 thì lượng bùn cat lơ lửng đến hồ là: Go = 6369 (tấn/năm), trong khi đó ưng với hiện trạng rừng năm 1993 thì lượng bùn cat lơ lửng đến hồ là  9235 (t?n/năm), như vậy, khi diện tích rừng trên lưu vực bị giảm thì lượng bùn cat gia nhập vào hồ sẽ tăng, đặc biệt trong mùa lũ. Trong mùa kiệt, nhìn chung thì khi diện tích rừng giảm thì dòng chảy có xu hướng tăng lên, mưc độ xói mòn bề mặt cũng gia tăng và mưc tăng này nổi trội trong mùa lũ còn trong mùa cạn thì lại có xu hướng giảm rõ hơn

Hiện tượng xói mòn lưu vực gây ảnh hưởng rất lớn đến lượng bùn cat đến hồ chưa. Để phòng tranh và giảm mưc độ xói mòn lưu vực cũng như giảm lượng bùn cat đến hồ chưa, cụ thể đối với lưu vực hồ chưa nước Đại Lải, có thể ap dụng cac biện phap sau:

- Tăng độ che phủ của rừng bằng cac biện phap như: trồng cây gây rừng ở thượng và hạ lưu, tăng cường cac biện phap bảo vệ rừng, giảm thiểu hiện tượng chặt pha rừng làm lương rẫy, khai thac rừng có quy hoạch. Đặc biệt là ở những nơi có mưc độ xói mòn cao.

- Giảm độ dốc của lưu vực: Thực hiện sản xuất nông nghiệp theo hình thưc ruộng bậc thang, trồng rừng theo những lô bậc thang, tạo thành những vành đai xen kẽ.

- Đào cac rãnh song song theo cac đường đồng mưc có tac dụng

Page 15: Gis Sample

làm giảm vạn tốc dòng chảy, ngưng tụ bùn cat.- Giảm thiểu sử dụng chất hoa học và thuốc trừ sâu trong sản xuất

nhằm giảm mưc độ ô nhiễm nước và cac chất độc hại trong nước…      4. Kết luận

Qua phân tích cac mô hình toan ở trên nhận thấy việc ưng dụng mô hình toan thông số phân bố để tính toan lượng dòng chảy bùn cat đến hồ và đanh gia ảnh hưởng của việc sử dụng đất đến bồi lắng hồ chưa là cần thiết. Qua đó nên ap dụng cac biện phap bảo vệ, phòng chống và giảm thiểu mưc độ xói mòn cũng như lượng bùn cat đến hồ đã nêu ở trên. Đồng thời nâng cao trình độ dân trí và thực hiện cac biện phap xoa đói giảm nghèo trong vùng, nâng cao nhận thưc người dân giúp cho việc bảo vệ đất, bảo vệ rừng và môi trường được tốt hơn nhằm giảm thiểu lượng bùn cat bồi lắng trong hồ, nâng cao tuổi thọ của hồ.Tài liệu tham khảo

1. Vũ Văn Tuấn. Đanh gia bước đầu ảnh hưởng của hồ chưa Hoà Bình đến môi trường. Tạp chí "Hoạt động Khoa học Công nghệ và Môi trường". Bộ Khoa học Công nghệ và Môi trường. 9-1998

2. Phạm Thị Hương Lan. Sử dụng mô hình toan thông số phân bố trong bài toan quy hoạch quản lý lưu vực. Tạp chí khoa học kỹ thuật Thủy lợi và Môi trường 11/2004

3. Nguyễn Sỹ Định, Đồ an tốt nghiệp năm 2005, giao viên hướng dẫn Phạm Thị Hương Lan.

      Hà Văn Khối, Mô hình tính toan chuyển tải bùn cat và bồi xói đối với hệ thống sông hoặc kênh, Tạp chí Cơ học, năm 2001.Abstract"Applied hydrology mathematical model to assess impact on land use to sedimentation of Dailai Reservoirs"One reason of sedimentation in reservoirs is the impact of human to land use in watershed.  Therefore, the impacting of land use on sedimentation in reservoir is necessary. This paper presents the Application of the SWAT Model on land use Impact Assessment on DaiLai Reservoir.

Introduction 123-129 và row từ 44-54 125-53129-59

A Geographic Information System is a type of application which has a set of facilities to capture, store, retrieve, maintain, and display geographic data and information. GIS applications are developed to meet many purposes, from simple purposes like GIS data exploration to sophisticated purposes like watershed mapping. Different commercial libraries are available for developers to use and implement in their applications, like ArcObject from ESIR and Map Suite from ThinkGeo. Unfortunately, the cost of license for these libraries is usually high, which makes the GIS application development process not viable for free lance programmers and small firms. In this series of tutorials, I am going to describe in detail how to build a desktop GIS application using the Open Source MapWinGIS library and C#. MapWinGIS is an ActiveX control for GIS development, with built-in support for many Raster and Vector formats.MapWinGIS.ocx is the core of MapWindow GIS, the well known Open Source, multi-purpose, GIS desktop application. The first step in reading this tutorial is acquiring MapWinGIS.ocx from the MapWindow GIS Open

Page 16: Gis Sample

Source project website, then installing it to your computer using the installation procedures provided by the project site.

Create Your Map

Preparation

In this tutorial, I am using .NET Framework 3.5 and Microsoft Visual Studio 2008 Professional Edition. Actually, you can use Visual Studio Express Edition without any problem. I am also using a set of GIS data in ESRI shapefile format, which I have provided above as a zipped file. I recommend you to download this data compressed file, decompress it, and place the file contents in an independent folder. Now, you are ready to go to the next step.

Create a Project and Add a Reference to MapWinGIS Components

Now, fire up your Visual Studio and create a new Windows Forms application. Point to the Project menu, then click Add Reference. In the Add Reference dialog box, point to COM tab, then select MapWinGIS Components from the Component Name list and click OK.

Now, you have a new reference in your project and you can show its name under References in the Solution Explorer.

Page 17: Gis Sample

Now, we are going to add the Map control to our toolbox. The Map control is a control used as a container and interactive display area for geographic data. To add this control to the toolbox, point to the General tab in the toolbox and right click. Select Choose Item from the menu. The Choose Toolbox Item dialog box will appear. Select the COM Component tab and then select Map Control. To add it to the toolbox, click OK.

Page 18: Gis Sample

Now, you can see the Map Control icon in the toolbox contained by the General tab.

Time to Create Your GUI

Now, it's time to build your interface. Drag a ToolStrip control from the Menu & Toolbars tab in the toolbox and drop it to the form. Add five buttons to the ToolStrip, and name these buttons toolCursor, toolZoomExtent,toolZoomIn, toolZoomOut, and toolPan. You can also assign meaningful labels and images to the buttons (you can use the images that I have in my project resources). Drag the Map control from the toolbox and drop it to the form. In the Properties window, set the Dock property of the Map control to Fill and set the CursorMode property to cmNone.

Load your GIS data to the Application Pragmatically

Page 19: Gis Sample

Now, we will add two ESRI Shapefiles for our map. The ESRI Shapefile or simply a Shapefile is a popular geospatial vector data format for geographic information systems software. In the Form1_Load event, add the following code:

 Collapse | Copy Code

//Add first layer to your mapint intHandler1; //integer index to handle the layer//create a new instance for MapWinGIS.Shapefile//MapWinGIS.Shapefile is a data provider for ESRI ShapefileMapWinGIS.Shapefile shapefile1 = new MapWinGIS.Shapefile();//Define the data source for MapWinGIS.Shapefile instanceshapefile1.Open(@"D:\GISSampleData\base.shp", null );//display the layer on the mapintHandler1 = axMap1.AddLayer(shapefile1, true);

//Add second layerint intHandler2;MapWinGIS.Shapefile shapefile2 = new MapWinGIS.Shapefile();shapefile2.Open(@"D:\GISSampleData\nile.shp", null);intHandler2 = axMap1.AddLayer(shapefile2, true);

In the first line, we have created an integer variable (intHandler1). In the second line, we have created an instance (shapefile1) for the MapWinGIS.Shapefile class. MapWinGIS.Shapefile is a container for geometric entities that represent real world geographic features. In the third line, the data source for the new object (shapefile1) is defined. This data source is an ESRI Shapefile. This data source shows Egypt as a polygon. In the fourth line, we have added this new object to our map control (axMap1) and made it visible. The function AddLayeris used to add a geographic layer to the map control and return an integer indicating the layer handler. Lines 4 to 8 add the second Shapefile to the Map control and make it visible. It is now time to run your first GIS application; strike F5 in your key board to show Egypt's map in the map control.

Page 20: Gis Sample

Change Your Feature Symbol

Customizing different symbology for different geographic features included in the map is one of the most important tasks for a GIS developer. In this lesson, I am going to present the easiest way to customize features symbology. Actually, MapWinGIS provides many advanced methods to symbolize GIS data, which I will discuss in an advanced lesson. Now, add the following code after the previous code in Form1_Load event:

 Collapse | Copy Code

//Set Filling color of the ploygon shapefileaxMap1.set_ShapeLayerFillColor(intHandler1, (UInt32)(System.Drawing.ColorTranslator.ToOle (System.Drawing.Color.SaddleBrown)));//Set the line coloraxMap1 .set_ShapeLayerLineColor (intHandler2 , (UInt32)(System.Drawing.ColorTranslator.ToOle (System.Drawing.Color.Yellow)));//Set the line widthaxMap1.set_ShapeLayerLineWidth(intHandler2,5);

Page 21: Gis Sample

In the first line, we use the set_ShapeLayerFillColor method of the Map control (axMap1). This method uses the layer handler (intHandler1) and a color in UInt32 format to set the fill color for the defined layer. There are many other useful methods provided by the Map control to customize the layer symbology, likeset_ShapeLayerFillStipple which defines the filling type of the layer, andset_ShapeLayerFillTransparency which defines the transparency level of the layer. In the second line, another method is used. This method - set_ShapeLayerLineColor - defines the color of line for line-geometry layers using the layer handler and the UInt32 format for color. In the third line, I have used theset_ShapeLayerLineWidth method to define the width of the line-geometry layer using this layer handler, and afloat number denotes the line width. Run your application to see how it displays your map now.

Add Some Actions to Your Map

Sure, you want to add some amazing actions like zoom in, zoom out, and pan for your map. Adding such actions is a very simple task with MapWinGIS. The CursorMode property for the Map control provides these tasks in an easy to use way; you have to assign the mode

Page 22: Gis Sample

that you want to this property to use it directly in your map. In the following code, I am going to play with the CursorMode property using the Click event for each button in my toolbar.

 Collapse | Copy Code

private void toolCursor_Click(object sender, EventArgs e){ axMap1.CursorMode = MapWinGIS.tkCursorMode.cmNone;}

private void toolZoomIn_Click(object sender, EventArgs e){ axMap1.CursorMode = MapWinGIS.tkCursorMode.cmZoomIn;}

private void toolZoomOut_Click(object sender, EventArgs e){ axMap1.CursorMode = MapWinGIS.tkCursorMode.cmZoomOut;}

private void toolPan_Click(object sender, EventArgs e) { axMap1.CursorMode = MapWinGIS.tkCursorMode.cmPan;}

To set your map to the maximum map extent, you will use the ZoomToMaxExtents method of the Map control. Just call this method using the Click event as follows to display your map in the maximum extent:

 Collapse | Copy Code

private void toolZoomExtent_Click(object sender, EventArgs e){ axMap1.ZoomToMaxExtents();}

Time to test these new features; run your application, and check every button.

Conclusion

MapWinGIS is the most easy way to create GIS desktop applications. The above features show the principle tasks required by a GIS programmer. Future lessons in this series will look at many useful and advanced features of MapWinGIS.

Introduction 

The objective of this series is to present a simple and easy to use approach to develop a desktop GIS application. My tool pack includes only MapWinGIS.ocx from MapWindow GIS Project which is one of the most successful open sourceGIS projects for Windows platform. MapWinGIS.ocx provides the full set of tools to maintain and display GIS data and it is free of charge under MPL license.

Page 23: Gis Sample

In the previous lesson, we discussed the basics required to display GIS data on the MapWinGIS.ocx Map Control. We also discussed how to customize the symbology of the displayed GIS data. In this lesson, I am going to teach you how to advance your symbology skills and use labeling functionality on your map.

As mentioned in the previous lesson, I am using .NET Framework 3.5 and Visual Studio 2008 professional edition in the code attached here, but you can use Visual Studio express edition to get the same results. You have to downloadMapWinGIS.ocx and install it on your machine too. You can download it from the official site of MapWindow Project. 

Attributes and Symbology 

One of the most amazing features of GIS is combining the description of the geographic entity with its geometry. Indeed, every geographic entity may describe using different attributes. For example, the attributes of land parcel may include area, perimeter, owner name, land use, etc. which these attributes may use to create different maps using different symbology approaches. In the previous lesson, we had used a simple symbology approach where all features in the GIS layer presented use a single symbol. In this lesson, we will know how we can create a quantitative map using attribute data.

According to ESRI Shapefile specification that was published by ESRI in July 1998, “Shapefile” technically means three files have the same name and different extensions:

1. *.shp is the main file that includes the geometric presentation of the geographic entities

2. *.shx is the index file, and 3. *.dbf is the attribute file

ESRI Shapefile uses Dbase IV DBF file format to store the attributes of the GIS layer. The data attached to this lesson is a single ESRI Shapefile that presents Arab League Countries. The attributes of this shapefile are organized in two fields CNTRY_NAME and POP_CNTRY. CNTRY_NAME is a text field which includes the name of the country.POP_CNTRY is an unsigned long integer field that includes the population of the country. 

Create Your GUI 

The GUI of our application is composed of a single Windows Form. This form has a tool strip named toolStrip1which has five buttons, toolCursor, toolZoomExtent, toolZoomIn, toolZoomOut and toolPan. The code of these buttons is discussed in the previous lesson. The form has a split container named splitContainer1 which is split vertically into two panels splitContainer1.panel1 to left and splitContainer1.panel2 to right. The left panel includes three buttons, btnReset, btnQuant and btnLablel. The right panel includes theMapWinGIS.ocx Map Control component named axMap1. You have also added a reference for MapWinGIS.ocx to your project. The previous lesson includes details for reference adding procedure.

The following figure shows the GUI of the application attached to this lesson:

Page 24: Gis Sample

Set Your Public Variables

I am using two public variables in this application. The first is an integer that denotes the layer handler and the second is MapWinGIS.Shapefile. These variables will be declared directly after the first clause of the class declaration as shown in the following:

 Collapse | Copy Code

//Create a layer handlerpublic int intHandler;//Create a new instance for MapWinGIS.Shapefilepublic MapWinGIS.Shapefile myShapefile = new MapWinGIS.Shapefile();

These items should be public because many methods will use these items. 

Create a SetBasicSymbology Method

This objective of this method is to set the symbology of the layer to a specific predefined symbology every time it is called. It does not return any value. The following code shows this method:

Page 25: Gis Sample

 Collapse | Copy Code

public void SetBasicSymbology(){ //Set Filling color of the polygon shapefile axMap1.set_ShapeLayerFillColor(intHandler,

(UInt32)(System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Honeydew))); //Set the outline color of the polygon features axMap1 .set_ShapeLayerLineColor(intHandler,

(UInt32)(System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Goldenrod)));}

Load Your Data

Now, we will load our data to our form, the following code should add to Form1_Load event:

 Collapse | Copy Code

private void Form1_Load(object sender, EventArgs e){ //Define the data source of Shapefile instance myShapefile.Open(@"D:\GISSampleData2\arabcntry.shp", null); //Display the layer on the map control intHandler = axMap1.AddLayer(myShapefile, true); SetBasicSymbology();}

This code loads the shapefile (D:\GISSampleData2\arabcntry.shp) into MapWinGIS.Shapefile instance (myShapefile), then adds it to the map control (axMap1) and stores its handler in intHandler. Finally, we will call SetBasicSymbology() to set the layer symbology to the basic symbology.

btnReset Code

The objective of btnReset is to reset the symbology of the layer to the basic symbology every time a user clicks it. The code of btnReset is the following: 

 Collapse | Copy Code

private void btnReset_Click(object sender, EventArgs e){ SetBasicSymbology();}

btnQuant Code

The code of btnQUnat is the main target of this lesson. This code customizes the layer symbology to show the population of each country using a spectrum of two colors. The first color is aqua color which illustrates the less populated country; another color is Dark Blue which illustrates the most populated country. Any country that has population among the

Page 26: Gis Sample

less and most population will be colored with a color among aqua and dark blue. To do that, you have to know which field in the shapefile table includes the population and calculate the minimum and maximum population.The code will be added to the btnQuant_Click event to let the user click this button and make his/her quantitative map that shows the population in the Arab League Countries.The code is the following:

 Collapse | Copy Code

private void btnQuant_Click(object sender, EventArgs e) { //Create a new instance for MapWinGIS.Table MapWinGIS.Table myTable = new MapWinGIS.Table(); //Define the data source of Table instance myTable.Open(@"D:\GISSampleData2\arabcntry.dbf", null); //Define the index of the field will used in symbology int myFieldIndex = 1; //Get the number of rows in the table int numberOfRows = myTable.NumRows; //Create an array to store the cell values of the field double[] myCellsValues = new double[numberOfRows]; //Populate the array with cell values restored from the Table instance for (int i = 0; i < numberOfRows - 1; i++) { myCellsValues[i] = System.Convert.ToDouble(myTable.get_CellValue(1, i)); } //Get the minimum and maximum values double minValue = myCellsValues.Min(); double maxValue = myCellsValues.Max();

//Create a new instance for MapWinGIS.ShapefileColorScheme MapWinGIS.ShapefileColorScheme myScheme =

new MapWinGIS.ShapefileColorScheme(); //Set the layer handler to the MapWinGIS.ShapefileColorScheme instance myScheme.LayerHandle = intHandler; //Set the field index to use in symbology myScheme.FieldIndex = myFieldIndex; //Create a new instance for MapWinGIS.ShapefileColorBreak MapWinGIS.ShapefileColorBreak myBreak =

new MapWinGIS.ShapefileColorBreak(); //Set the minimum value in the field as a start value myBreak.StartValue = minValue; //Set the start color of the scheme myBreak.StartColor = (UInt32)(System.Drawing.ColorTranslator.ToOle

(System.Drawing.Color.Aqua)); //Set the maximum value in the field as an end value myBreak.EndValue = maxValue; //Set the end color of the scheme myBreak.EndColor = (UInt32)(System.Drawing.ColorTranslator.ToOle

(System.Drawing.Color.DarkBlue)); //Add the break to the color scheme myScheme.Add(myBreak); //Upgrade display using the scheme axMap1.ApplyLegendColors(myScheme); }

Page 27: Gis Sample

In the first line, we declare and initiate a new instance of MapWinGIS.Table class and name it myTable. This class is designed to present the table of ESRI Shapefile. The instance of this class includes a collection of instance for Field class. Each Field instance is used to present a field in the table of shapefile. The instances have zero-based index. Each Field instance has a collection of instances for CellValue class. CellValue instance presents the values of the cells organized in a Field instance.

In the second line, we load our dbf table in MapWinGIS.Table instance (myTable) using Open method.

In the third line, we declare an integer (myFieldIndex) and assign one to him. This integer is used to identify the field we will use in symbology as the second field (POP_ CNTRY).

The fourth line is used to get the number of rows in the table using NumRows method of MapWinGIS.Tableinstance (myTable).

In the fifth line, we declare and create an array (myCellsValues) composed of a number of double elements equal to the number of rows in the table.

Now, we will use For loop to populate our new array (myCellsValues) by the values of CellValue instance inmyTable. Then we will get the minimum and maximum values in the array using Min and Max methods for array.

The minimum and maximum values are assigned to two variables minValue and maxValue of double type. 

Now, we will declare and create a new instance for MapWinGIS.ShapefileColorScheme class and name itmyScheme. This class is designed to describe the complex color scheme for the layer based on the values stored in the shapefile table field. The scheme is joined to a specific layer by the handler of this layer, and to the field by the field index. The instance of this class has a collection of MapWinGIS.ShapefileColorBreak instances.

MapWinGIS.ShapefileColorBreak class is used to describe a color theme used to color the geographic entities in the layer based on a region of values. This region of values is limited by two properties for eachMapWinGIS.ShapefileColorBreak instance: StartValue and EndValue. The color of theme is identified by two another properties for the instance: StartColor and EndColor.

In this application, I had used one MapWinGIS.ShapefileColorBreak instance named myBreak, and I had assigned the minValue and maxValue to StartValue and EndValue properties respectively. Also, I had assigned aqua and dark blue colors to StartColor and EndColor properties respectively.

After assigning the properties of the MapWinGIS.ShapefileColorBreak instance (myBreak), I had used Addmethod to add it to MapWinGIS.ShapefileColorBreak instances collection of myScheme.

Page 28: Gis Sample

The final step is to use ApplyLegendColors method of Map Control (axMap1) to use this scheme to symbolize the layer.

Now, strike F5 to run the application and click btnQuant button to get your new map. 

Add Labels to Your Map

Labels are very important to make your map meaningful. Most of the GIS users and developers use values stored in the table to label their features, and that is what I am going to do. Add the following code to btnLabel_Clickevent:

 Collapse | Copy Code

private void btnLabel_Click(object sender, EventArgs e) { //Define a string to store the label of the feature string myLabel; //define two double variables to use as a coordinates for label position double x, y; //Use a loop to read the cell value that is used as a label and

//set the label on the map for (int i = 0; i < myShapefile.NumShapes -1; i++)

Page 29: Gis Sample

{ //assign the value of the cells of the field number zero to the label myLabel = System.Convert.ToString( myShapefile.get_CellValue(0, i)); //Calculate the x position for the label x = myShapefile.get_Shape(i).Extents.xMin + (myShapefile.get_Shape(i).Extents.xMax -

myShapefile.get_Shape(i).Extents.xMin) / 2; //Calculate the y position for the label y = myShapefile.get_Shape(i).Extents.yMin + (myShapefile.get_Shape(i).Extents.yMax -

myShapefile.get_Shape(i).Extents.yMin) / 2; //add the label on the map axMap1.AddLabel( intHandler, //Layer handler myLabel, //Label string (UInt32)(System.Drawing.ColorTranslator.ToOle (System.Drawing.Color.Black)), //Color of the label x, y, //Position of the label MapWinGIS.tkHJustification.hjCenter //Justification of the label ); } }

To add labels for your map, you have to know which field includes the values of labels and where you will set the labels on the map.

In the previous code, I was creating a string variable named myLabel and two double variables x and y to use to locate the label on the map. Then, I was using the for loop to read the cell values from the first field for all shapes in the shapefile, and each loop I was assigning this value to (myLabel) string variable and getting the position of the label as the center of the shape.

Finally, I was using AddLabel method of Map Control (axMap1) to add this label (myLabel) using Black color as a font color in a position identified by x and y.

Now, strike F5 to run the application and click btnLabel to show the label on your map.

Page 30: Gis Sample

Now, we have many useful ideas to use MapWinGIS.ocx to build a GIS application. In the next lesson, together we are going to explore how useful arial photographs and satellite images can be for our applications.

Introduction

In the previous lessons, we had learned how to display and manage vector data using MapWInGIS.ocx and embed these functions in a Windows application developed using C#. In this lesson, I am going to teach you how to manage raster data in the same manner. The objectives of the reader are to understand how to add the raster layer to the map control, how to manipulate the raster symbology, how to get the raster information, and how to join the cursor to the location on raster. As usual, my tools pack includes MapWinGIS.ocx, which is an ActiveX control that can be used in any language that supports ActiveX (e.g., C#, VB, Microsoft Access, Microsoft PowerPoint, … ).MapWinGIS.ocx is Open Source, and you can download it free of charge under the MPL license. All code examples and screenshots in this article are based on the Microsoft Visual C# 2008 Professional Edition, but the reader can use Microsoft Visual C# Express Edition to get the same results.

Build a Desktop GIS Application Using MapWinGIS and C# - Part 1

Page 31: Gis Sample

Build a Desktop GIS Application Using MapWinGIS and C# - Part 2

Raster Data in GIS

Raster data is a very common and useful data model in GIS. Any raster may be introduced as an array of columns and rows. A row intersects a column to create a rectangular area called raster cell. In the most common raster forms, the width of the column equals the height of the row, so the raster cell shape is square. The raster cell often represents a squared area on the study area. Each cell has two identifiers (X, Y) that demonstrate the coordinates of the cell location. The first identifier/coordinate, X, denotes the column that passes across the cell. The second identifier/coordinate, Y, denotes the row that passes across the cell. In general purpose raster formats like Joint Photographic Experts Group (JPEG) and Graphical Interchange File Format (GIFF), X, Y express directly the number of columns and rows that pass across the cell, but in GIS raster data format, these coordinates are connected to the world coordinate system to describe the geographic location of the cell in real life.

Raster cells are usually illustrated using a digital value which may be discrete (integer-like data types) or continuous (real-like data types). These digital values are used to represent geographic features. For example, digital values may be 1 to describe the existence of a feature, and 0 to describe the absence of a feature. The following figure shows how to illustrate a geographical feature using these previous two values (1 and 0), where the blue squares express the cells marked with one, and white squares express the cells marked with zero.

Page 32: Gis Sample

The discrete digital values in GIS raster data are used to model discrete phenomenon like land use and administrative units, where continuous digital values are often used to represent continuous phenomenon like terrain elevation and soil acidity. GIS professionals know many ways to get raster data. They can produce it directly using different tools like automatic scanning and vector data rasterization. They can get raster data as aerial photographs and remotely sensed data.

Sample Application

The sample application in this lesson demonstrates many features of GIS raster data manipulation usingMapWinGIS.ocx. In the following sections, I will discuss these features in detail, and I will ignore the features that were discussed in the early lessons.

Ready, Steady, Gooooooo

In the beginning, you have to start a new Windows application. Give your project a name. I named mine "GISSampleApplication3". In the Solution Explorer window, select the project node, right click on it, and select Add Reference from the context menu. Use the COM tab in the Add Reference window that will appear, findMapWinGIS.ocx in the list, and add it. Now, you have all the functionalities of MapWinGIS.ocx in your project, but you still need to add the visualization functionality provided by the MapWinGIS.ocx Map control. To add this control to your toolbox, select the General tab in the toolbox, right click on it, select Choose Items from the context menu, select the COM component tab from the Choose Toolbox Items window, find the Map control, check it, and press OK. Now, the Map control tool will be shown in your toolbox. The above steps are described in detail with illustration inlesson 1.

Give me Something to See

The sample application of the current lesson is a simple, single-form application. This form has a ToolStrip namedtoolStrip1 which has five buttons: toolCursor, toolZoomExtent, toolZoomIn, toolZoomOut, andtoolPan. The

Page 33: Gis Sample

code for these buttons is discussed in lesson 1. The form also has a status bar namedStatusStrip1docked at the bottom. The status bar contains a ToolStripStatusLabel calledToolStripStatusLabel1. The form has a SplitContainer named splitContainer1 which is split vertically into two panels: splitContainer1.panel1 to the left and splitContainer1.panel2 to the right. The left panel includes a single button named tbnInfo. The right panel includes the MapWinGIS.ocx Map Control component named axMap1 which is docked to fill the right panel completely.

Let's Write Some Code

Now it's time for some real work. We will now discuss the required code to achieve our lesson's objectives and its meaning. After the beginning brace of the declaration of the Form1 class, add the following code:

 Collapse | Copy Code

#region PublicDeclaration//(1) Create an integer variable to store the raster grid layer handlerpublic int intHandler;//(2) Create an instance for the grid raster public MapWinGIS.Grid myGrid = new MapWinGIS.Grid();//(3) Create a new grid header objectpublic MapWinGIS.GridHeader myHeader = new MapWinGIS.GridHeader();//(4) Create an image instance to store and display the rasterpublic MapWinGIS.Image myImage = new MapWinGIS.Image();#endregion

This set of type declaration shows the four main types required to manipulate the raster grid data in MapWinGIS. The first type is the layer handler which is stored in an integer variable (intHandler). The layer handler is a unique value used to manipulate the layers. The second type is MapWinGIS.Grid. This is a specific MapWinGIS type used to store the raster grids. The third type is MapWinGIS.GridHeader, which is another type provided by MapWinGIS to manipulate the raster header. The fourth type is MapWinGIS.Image. It is a type provided by MapWinGIS, and is used to store an image copy of the raster, which can be used to visualize the raster grid data in the Map control. All pervious MapWinGIS types are reference types, and require the new keyword to be initiated.

Now we have all the required instances to manipulate our raster. The raster used in this lesson is a sample digital elevation model DEM for a study area in the north western desert of Egypt created by achieving an interpolation for a set of elevation points collected from the field and from topographic maps. This raster is stored in GeoTIFF format. The GeoTIFF format is a regular TIFF format with additional information about the spatial domain of the data. Add the following code in the Form1_Load event:

 Collapse | Copy Code

#region LoadTheData//(1) Open the gridmyGrid.Open(@"D:\SampleData\dem.tif", MapWinGIS.GridDataType.DoubleDataType, false,MapWinGIS.GridFileType.GeoTiff, null);//(2) Get the header of the rastermyHeader = myGrid.Header;

Page 34: Gis Sample

//Symobolize the raster grid//(3) Create a raster grid color schemeMapWinGIS.GridColorScheme myScheme = new MapWinGIS.GridColorScheme(); //(4)Assign the no data color to lackmyScheme.NoDataColor = System.Convert.ToUInt32( System.Drawing.ColorTranslator.ToOle( // System.Drawing.Color.FromArgb(0, 0, 0)));//(5) Set the attributes of the color schememyScheme.UsePredefined( (double)myGrid.Minimum, (double)myGrid.Maximum, MapWinGIS.PredefinedColorScheme.DeadSea );

//Convert the grid to an image//(6) Create a Utili instanceMapWinGIS.Utils myUtil = new MapWinGIS.Utils();//(7) and use it to convert the grid to the imagemyImage = myUtil.GridToImage(myGrid, myScheme, null);

//(8) Finally add the layer to the mapintHandler = axMap1.AddLayer(myImage, true);#endregion

The first step to display the data is to load the raster data from the file to the grid instance (myGrid). The Openmethod is used to load the data into the grid instance. The Open method needs five arguments:

The first argument is the full path to the file that contains the raster data. The second argument is the type of grid data which is presented in MapWinGIS as an

enum typeMapWinGIS.GridDataType, which represents six elements. These elements include four defined elements (ShortDataType for short integer data type pixels, LongDataType for long integer data type pixels,FloatDataType for single precision data type pixels, and DoubleDataType for a double precision data type pixels) and two undefined elements (UnknownDataType for use with unknown data types, andInvalidDataType for invalid data types).

The third argument is a bool value that shows if the raster should read from RAM (true) or from file (false).

The fourth argument is a GridFileType. MapWinGIS provides an enumeration to describe the grid file type supported by MapWinGIS itself. The supported grid file types are: ASCII grid file format (MapWinGIS.GridFileType.Ascii), Band Interleaved by Line format (MapWinGIS.GridFileType.Bil), Binary grid file format (MapWinGIS.GridFileType.Binary), Digital Terrain Elevation Data file format (MapWinGIS.GridFileType.DTed), ERMapper Compressed Wavelet file format (MapWinGIS.GridFileType.Ecw), ESRI Grid file format (MapWinGIS.GridFileType.Esri), ArcView Binary Raster file format (MapWinGIS.GridFileType.Flt), GeoTIFF raster file format (MapWinGIS.GridFileType.GeoTiff), MrSID raster file format (MapWinGIS.GridFileType.MrSid), PCI PAux raster file format (MapWinGIS.GridFileType.PAux), PCI Geomatics database file format for raster data (MapWinGIS.GridFileType.PCIDsk), and United States Geological Survey USGS Spatial Data Transfer Standard raster data format (MapWinGIS.GridFileType.Sdts).

Page 35: Gis Sample

Beside these types, the user can assign two different enums:MapWinGIS.GridFileType.InvalidGridFileType, which may be used to handle data with gaps or errors, and MapWinGIS.GridFileType.UseExtension, which lets the user open different common raster formats.

The last argument required for the Open method is the callback. null is assigned for this argument in most common cases.

The second step is to assign the grid header to the header instance (myHeader). The grid header includes basic information about the raster grid like its width, height, pixel resolution etc. After the second step, the grid and its header are loaded to the computer memory, and for that reason, the procedure requires a time. The objective of steps 3, 4, and 5 is to prepare the symbology required to display the grid. The third step is a creation of the raster grid color scheme. The raster grid color scheme is presented by the MapWinGIS.GridColorScheme class in MapWinGIS. In step 3, an instance (myScheme) of this class is created and initiated.

In the fourth step, we will set a color to illustrate the no-data pixels using the NoDataColor property of theMapWinGIS.GridColorScheme instance (myScheme). The assigned color is black. The fifth step is to use theUsePredefined method for the instance myScheme to assign a predefined grid color scheme setting for mySchemesettings. This method requires three components: the minimum pixel value, the maximum pixel value, and the predefined grid color scheme. The minimum and maximum pixel values can easily be got using the grid instance properties Minimum and Maximum. The predefined grid color scheme introduced in MapWinGIS as an enumeration type includes eight elements:

MapWinGIS.PredefinedColorScheme.DeadSea MapWinGIS.PredefinedColorScheme.Desert MapWinGIS.PredefinedColorScheme.FallLeaves MapWinGIS.PredefinedColorScheme.Glaciers MapWinGIS.PredefinedColorScheme.Highway1 MapWinGIS.PredefinedColorScheme.Meadow MapWinGIS.PredefinedColorScheme.SummerMountains MapWinGIS.PredefinedColorScheme.ValleyFires

And now, it’s show time. Let's add the code required to display our grid. To display the grid, you have to convert it to an image. Conversion of a grid to an image requires an instance of the MapWinGIS.Utils class. In step 7, this instance (myUtil) is created and initiated. In step 8, the method GridToImage - which is provided byMapWinGIS.Utils (myUtil) – is used to convert the gird – the first argument (myGrid) – to an image using a defined grid color scheme – the second argument (myScheme). The third argument required for the GridToImagemethod is the callback. Now, add the image (myImage) to the Map control (axMap1) using the AddLayer method. Don't forget to assign the required code to the navigation buttons. The code for these buttons is available in lesson 1. Now, strike the F5 function key in your keyboard to start debugging the application, and if you did everything right, you will get the following screen:

Page 36: Gis Sample

Something About my Grid

Each raster grid has a set of basic information – called metadata in some technical literature – which is required to understand many facts about the grid and the geographic features presented by the grid. The most common and important information icludes the pixel dimensions in measurement unit (e.g., Meter), the width and the height of the grid in pixels, and the lower left corner coordinates. This information helps the programmer to know and calculate many useful information like the width and the height of the grid in the measurement unit (width (or height) in measurement unit = width (or height) in pixels * pixel edge length), the area of the grid (width in pixels * height in pixels * pixel edge length * pixel edge length). All these basic data are available in the GridHeader instance (myHeader). Add the following code to the btnInfo_Click event:

 Collapse | Copy Code

//(1) Get the width and height of the //grid in pixelsint width = myHeader.NumberCols;int hight = myHeader.NumberRows;string sizeInPixels = String.Format("Grid sizs - in pixels - is ({0},{1})\n", width, hight);

//(2) Get the width and height of the pixeldouble deltaX = myHeader.dX;double deltaY = myHeader.dY;string pixelDimensions = String.Format("Pixel dimensions are ({0},{1})\n", deltaX, deltaY);

//(3) Get the lower left corner coordiantesdouble xLlLocation = myHeader.XllCenter;double yLlLocation = myHeader.YllCenter;

Page 37: Gis Sample

string lowerLeftCorner = String.Format("Lower Left corner coordinates ({0},{1})\n", xLlLocation ,yLlLocation ); //(4) Show the messagestring infoMessage = sizeInPixels + pixelDimensions + lowerLeftCorner;MessageBox.Show(infoMessage, "Raster Information", MessageBoxButtons.OK, MessageBoxIcon.Information);

In the first set of statements, the properties NumberCols and NumberRows of the GridHeader instance (myHeader) were used, and the restored values stored in the width and height integer data variables. These properties restore the number of columns and the number of rows, respectively. In the second set, the properties dXand dY of the GridHeader instance (myHeader) were used, and the restored values stored in the deltaX anddeltaY integer data variables. In the third set, the properties xllCenter and yllCenter of the GridHeaderinstance (myHeader) were used, and the restored values stored in the xLlLocation and xLlLocation integer data variables. These two variables represent the coordinates of the center of the lower left corner pixel. The fourth and the last set of the code is where we will build a string to represent the previous information and launch it visually to let the user read it. Strike the F5 function key in your keyboard. You will get something like this as the output:.

Tell Me, Where Am I???

Some of the most important functions GIS provides are where it is and what it is. For raster data, this information can be introduced using the PixelToProj method for the Map control instance and the get_Value method for the Grid instance, respectively. Go to Form1 in Design view and select the axMap1 control. Press F4 to get axMap1's Properties window. Find the SendMouseMove property in axMap1's Properties window and set it to true. This action will activate axMap1_MouseMoveEvent. Now, bring this event axMap1_MouseMoveEvent for the axMap1 event list, and double click it to open it in Code view. Add the following code for this event:

 Collapse | Copy Code

//(1) Get the location of the cursor// form the MapControl and transform it to//the projection locationdouble X =0;double Y =0;axMap1.PixelToProj(e.x, e.y, ref X, ref Y);//(2) Get the value of pixel at specified point

Page 38: Gis Sample

double pixelVal = (double) myGrid.get_Value(e.x, e.y);//(3) Print the result to the status toolbar.string pointLocation = String.Format("Cursor location ({0},{1}) " + "and the pixel value is {2}",X,Y, pixelVal );toolStripStatusLabel1.Text = pointLocation;

The first set of code aims to identify the location of the cursor on the axMap1 control. In this code, we will declare two double type variables X, Y, and assign an initial value (0) for both. The PixelToProj method for the axMap1instance is used, and it needs four arguments: the first two arguments are the position of the cursor on axMap1, which is represented by e.x and e.y, and the variables where the converted value will be stored. These variables, X,Y, should be passed using the keyword ref. After using this method, the values of X and Y will store the location of the cursor on axMap1 in the projection measurement unit. The second set of code aims to identify the value of the pixel where the cursor is. In this code, we will declare a double type variable pixelVal and assign a value returned by the method get_Value for the Grid instance (myGrid). The method get_Value requires two arguments representing the location of the cursor. These arguments are represented using e.x and e.y. Now, strike F5, and try to move the cursor above the map and show how the status bar will change directly to show you the location of the cursor and the value of the pixel located in this location.

Conclusion

MapWinGIS presents an easy-to-use approach to display and manipulate raster data in a two level manipulation. The first level treats the grid so the programmer can return information like the width and the height of the grid or the lower left corner coordinates. The second level treats the grid data on the pixel level, where the programmer can set or return the value of the pixel using its location. Using the same toolbox, programmers may display and manipulate images which add great functionality for GIS programmers and support their applications that include procedures to handle complex raster formats like multispectral images and aerial photographs.

Preface

This lesson is part 4 of a series of lessons aimed to show the capabilities of MapWinGIS.ocx to develop Windows-based desktop GIS standalone applications using C#. If you are reading about MapWinGIS.ocx the first time, I strongly recommend reading the previous three articles before. These articles are available here: Part 1, Part 2, andPart 3.

Introduction

Many GIS specialists believe that data creation is one of the most important GIS activities. GIS data may be created in different ways, it may draw directly or be imported from secondary sources. In this article, I am going to discuss how to manage data creation using MapWinGIS.ocx and C#. I am using .NET Framework 3.5 and Microsoft Visual Studio 2008 Professional Edition. Actually, you can use Visual Studio Express Edition without any problems. Also, you have to install MapWinGIS.ocx in your machine. Finally, the data used in this article is attached as a zipped file.

Objective

Page 39: Gis Sample

The objective of the following program is to create a point shape file using secondary data stored in comma separated values in *.csv text format. A CSV file is a specially formatted plain text file which stores table-style information in a very simple format, with one record on each line, and each field within that record separated by a comma. In this tutorial, a series of locations were stored in a CSV file named road.csv. Each location was described using three parameters. The first parameter is the ID which is the integer index. The second and third parameters are the location coordinates in a Universal Transverse Mercator metric coordinate format. The following figure shows the contents of the road.csv file shown in Notepad++ software.

I have to mention here that many data gathering devices such as GPS and echo sounders can export gathered data. For instance, NMEA 0183 files that download from GPS devices is some kind of CSV file format.

Methodology

Three main problems should be considered by the programmer when working on CSV to shape file conversion software. These problems are how to create a new shape file, how to read CSV file contents and parse it properly, and finally, how to create the shapes and add it to the shape file. The following figure shows a detailed methodology to convert a CSV file to a shape file.

Page 40: Gis Sample
Page 41: Gis Sample

The first step is to create a new shape file instance using the MapWinGIS API. The second step is to add a new index field for the new shape file table. It is recommended to add at least one field to the shape file in the creation phase. In this example, the index field will be the integer data type. These steps represent the first task to be considered by the developer, which is the shape file creation task. After finishing this task, we have an empty shape file. If we terminate the program at this point, we will lose the shape file, because it is empty. The shape file should include some shapes to be a real shape file, and has a location and size on the storage media. Before adding the shapes for the shape file, we have to create these shapes using data provided by the CSV file. So, the next task is to open the CSV file and read its contents. The third step is to open the CSV file. This is a very easy step because, this file is a text file. Reading the CSV file contents line by line and analyzing the line to extract the ID, x, and y data is the fourth step. Analyzing the CSV line is done using secondary subroutines. These subroutines introduce the fourth step. The fifth step is to create the shapes using the MapWinGIS API. After creating the shapes, the shapes should be added to the shape file, which is the sixth step. Steps from four to six will repeated while the CSV file still has rows to read. The final step is to save the shape file.

Time to write some code

I think we have a complete road map to develop a simple software to convert a CSV file to an ESRI shape file. So, let's write some funny code. In this tutorial, we will use a console application template. Start your Visual Studio and create a new Console Application project. We need to add a reference to MapWinGIS. You can get a detailed description of how to add this reference for your project in the first tutorial in this series. Before writing the core of our code - the CSV to shape file conversion code - we have to develop a simple code to parse the CSV file contents. The following code box shows three static methods: GetIndex, GetX, and GetY, where each method receives a CSV raw and returns a specific component from this raw (Index, X, Y field values).

 Collapse | Copy Code

private static double GetY(string sentence){ string strY = sentence.Substring(sentence.LastIndexOf(";") + 1); double result = Convert.ToDouble(strY); return result;}

private static double GetX(string sentence){ string strNewSentense = sentence.Substring(sentence.IndexOf(";")+1); string strX = strNewSentense.Substring(0, strNewSentense.IndexOf(";")); double result = Convert.ToDouble(strX); return result;}

private static Int16 GetIndex(string sentence){ string strId = sentence.Substring(0, sentence.IndexOf(";")); Int16 result = Convert.ToInt16(strId); return result;}

Back to the main method for the console project, where we will write the core code. In the first line, add the code required to create a new instance (myShapefile) for the Shapefile class. In the second line, use the methodCreateNew to create a new

Page 42: Gis Sample

physical shape file by assigning its full path and its geometry type. The geometry type for the shape file is defined by the ShapefileType enumerator. This enumerator can define 14 geometry types. The most common geometry types provided by this enumerator are SHP_POINT, SHP_POLYLINE, and SHP_POLYGON for the point, polyline, and polygon geometry types. It is strongly recommended to add a new field for your shape file table when you do new shape file creation, regardless of whether you add values for this field cells or not.

The third line shows how to create a new instance (myField) for the MapWinGIS.Filed class. The following three lines show how to set the field properties. There are many available field properties, but the common properties are those three. The first property is Name, which is a string and is assigned as the name of a new field. You have to note that; the Shapefile format use the old format *.dbf to store attributes; you have to consider all the restrictions of file naming in your work. This means, the name string should be less than 12 letters, and not include special characters or spaces. The second property is Type, which defines the data type that can be stores in this new field. MapWinGIS provides an enumerator (FieldType) that includes all the available data types that may be accepted by the Field class. This enumerator provides DOUBLE_FIELD, INTEGER_FIELD, and STRING_FIELD for double precision, integer, and string data, respectively. The third property is the Width. This property defines the width (how many letters or digits) for the field. Integer values only set to this property. Finally, we have to add this new field for the table. The method EditInsertField of the instance myShapefile is used to add the new field for the table. You have to note this: using this method requires you to set the value of the table object EditTableproperty to be true. Fortunately, when we use the CreateNew method, both the EditTable and EditShapeproperties are automatically set to true.

 Collapse | Copy Code

//Create new shapefileShapefile myShapefile = new Shapefile();//Define the path of the new shapefile and geometry typemyShapefile.CreateNew(@"D:\GISLesson04\road.shp", ShpfileType.SHP_POINT);//Create new fieldMapWinGIS.Field myField = new Field();//Set the field propertiesmyField.Name = "ID";myField.Type = FieldType.INTEGER_FIELD;myField.Width = 10;//Add the filed for the shapefile tableint intFieldIndex = 0;myShapefile.EditInsertField(myField, ref intFieldIndex, null);

Now we have a new shape file with a single field table ready to use. If we finish the application in this situation, MapWinGIS will delete the shape file physically because there is no meaning for a shapeless shape file. You have to add at least one shape file to be accepted by MapWinGIS to save this new shape file. However, we have a CSV file full of data needed for the drawing and that what we will do in the following section. To read the contents of the CSV file - remember, a CSV file is a text file - we use the StreamReader instance (myFile), and then we can use this as a stream reader instance to read the contents of the CSV file line by line using a while loop. This loop will stop when it arrives at the end of the CSV file. Within the while block, with each loop, we will create a new instance (myShape) of the Shape class. The Shape class defines the shapes inside the shape file. Each Shape includes one or more points. This new instance

Page 43: Gis Sample

should be created using the method Create for the instance myShape. This method requires an argument that defines the geometry of the shape. This geometry is provided by the enumeratorShapefileType which was mentioned before. After creating the Shape instance myShape, we have to draw it - or define it spatially - using the point data in the CSV file. To do that, we have to create a new instance for the Pointclass called myPoint. This instance has two properties (x, y) which define the location of the point. Now is the time when the parsing methods designed before will be useful. We will use the GetX and GetY methods to get the x and y value from the CSV line, and set these values to the myPoint (x ,y) properties. After creating the point, we will add it to the Shape instance (myShape) using the method InsertPoint. Then, we will add this shape to the shape file instance (myShapefile) using the method EditInsertShape.

 Collapse | Copy Code

System.IO.StreamReader myFile = new System.IO.StreamReader(@"D:\GISLesson04\road.csv");// Using while loop to read csv file line by linewhile ((myLine = myFile.ReadLine()) != null){ if (myCounter > 0) { MapWinGIS.Shape myShape = new Shape(); myShape.Create(ShpfileType.SHP_POINT); MapWinGIS.Point myPoint = new Point(); myPoint.x = GetX(myLine); myPoint.y = GetY(myLine); int myPointIndex = 0; myShape.InsertPoint(myPoint, ref myPointIndex); myShapefile.EditInsertShape(myShape, ref myShapeIndex); myShapeIndex++; } myCounter++;}

When the while loop reaches the end of the CSV file, every line in the CSV file will match a point in the shape file. The final step is to stop editing the shape file. To do that, we have to use the method StopEditingShapes of themyShapefile instance. Now, you can display your new shape file using any GIS software. You may display it using the MapWinGIS application as we did before in the early lessons. For me, I will display the shape file in MapWindowsGIS, which is the Open Source desktop GIS application for Microsoft Windows built completely on MapWinGIS.

Page 44: Gis Sample